You need to sign in to do that
Don't have an account?
Apex Rest Callout GET Method with parameters
Apex Rest Callout GET Method with parameters
I need to call a GET web service method that contains parameters to be passed along.
When I m calling that from POSTMAN with the access token,etc.. I m getting response
https://apiabcdef.test.abcdexyz.com/api/tcUser?Query=UserCode = 'USER_0706'
But when I m calling this from Apex it is giving a bad request error. code below
public static HttpResponse getUserIDFromTCheck(String token, string userCode) {
//JSONParser parser = JSON.createParser(token);
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint( 'https://apibibforceapi.test.tyrecheck.com/api/tcUser?Query=UserCode = \''+userCode+ '\' ');
httpReq.setMethod('GET');
httpReq.setHeader( 'Content-Type', 'application/json' );
httpReq.setHeader( 'Authorization', 'Bearer ' + token );
Http http = new Http();
HttpResponse httpRes = http.send( httpReq );
//System.debug('#test2 The status code returned from second service : ' + httpRes.getStatusCode() + ' : ' + httpRes.getStatus());
return httpRes;
}
this code gives error as :
getStatusCode : 400
getStatus : Bad Request
Please let me know is this the right way to call a GET third party webservice.
Just to make sure, Did you add 'https://apibibforceapi.test.tyrecheck.com' as remote site in your salesforce org?
if not, Please add it as remote site setting.
To add a remote site setting:
- From Setup, enter Remote Site Settings in the Quick Find box, then select Remote Site Settings.
- Click New Remote Site.
- Enter a descriptive term for the Remote Site Name.
- Enter the URL for the remote site.
- Optionally, enter a description of the site.
- Click Save.
Let me know if it works...Best,
Nithesh
Thanks Nithesh,
yes that is already added as I m calling many other API from same domain
Check whether the URL has any blank space and the userCode is already a string, so you may not need use those quotes.. Just try these and let me know if any of them works.
Hi Nithesh,
Thanks again for looking so closely to it, but that I discussed that with the API team before posting a question here to developer forum, they wanted and highly recommend for that space.
Even if I remove the space from Postman it does not work in postman too, below is the snapshot from postman removing that space.
Do we have any solution for this issue, I am facing the exact same issue while passing string parameters in a 'GET' request. The exact url is working absolutely fine in POSTMAN but not while invoking from Salesforce. All remote site settings setups are successfully done.
Can anyone please help. Need this on an urgent basis.
Example: https://example.com?$parameter=%20value