You need to sign in to do that
Don't have an account?
Jatin Gupta 21
HTTP Response 400
I am using HTTP POST for submittig data to an external application.
With Postman the request gives Resonse as expected with HTTP response code of 200.
But while doing the same with apex class and HTTP Request/Response the response is Bad Request, StatusCode=400.
I have tried with different content-type but the error persists.Can anybody help me out ?
With Postman the request gives Resonse as expected with HTTP response code of 200.
But while doing the same with apex class and HTTP Request/Response the response is Bad Request, StatusCode=400.
I have tried with different content-type but the error persists.Can anybody help me out ?
string start_date = '2020-04-01 17:00'; // space between 01 and 17.
string to_date = System.now().format('YYYY-MM-dd HH:mm'); //space between dd and HH
You will haven to encode the parameters before appending the endpoint or try using %20 to replace the space.
All Answers
Bad Request 400 means that your request isn't weel formatted.
Postman enrich the request with full information, althougth in Salesforce you must pay attention on header information and also body.
Pay attention also on header info hide from Postman, for example if you pass base64 on your body, or a binary expecially, you can encounter problems.
An example of hidden info in header in Postman, these info must be filled also in Salesforce where you don't have an automism to enrich your request.
Give us more details to help you if you need
I have already done the same exercise as suggested by you.i.e. getting all header information from postman to salesforce Apex.I am getting the same result.
I have set the body as blank in the request .I have set the endpoint only.Do I need to do anything for setting the body ?
httpresposne.getBody() returns blank whereas httpresponse returns System.HttpResponse[Status=Bad Request, StatusCode=400]
Can you share your apex code snippet if possible? It looks like parameters are not passed in the proper format. Thanks
string url = 'https://www.t............html?';
string key = '***********';
string profile_id = '*********';
string userid = '*********';
string start_date = '2020-04-01 17:00';
string to_date = System.now().format('YYYY-MM-dd HH:mm');
string endpoint = 'userid='+userid+'&profile_id='+profile_id+'&key='+key+'&from_date='+start_date+'&to_date='+to_date+'&limit=10&page_no=2';
System.debug('>>>> endpoint >>>>>' + url+endpoint);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader('Content-Type', 'application/json');
request.setEndpoint(url+endpoint);
request.setMethod('POST');
request.setBody('[{}]');
system.debug('====URL===='+request.getEndpoint());
system.debug('====Header===='+request.getHeader(key));
HttpResponse response = http.send(request);
Have you tried removing this line? request.setBody('[{}]');
string start_date = '2020-04-01 17:00'; // space between 01 and 17.
string to_date = System.now().format('YYYY-MM-dd HH:mm'); //space between dd and HH
You will haven to encode the parameters before appending the endpoint or try using %20 to replace the space.
Can you see what the debug logs print in salesforce for endpoint and compare it with that of postman and check if there is any difference
Thanks
Now I have identified the issue.Any blank space should be replaced with %20.It worked for me.
a link to do what?
Please explain better your need
Claudio