+ Start a Discussion
NSK000NSK000 

how to call an url from salesforce

Hi guys,

I'm having issues calling an url from salesforce. 
Here is th code.
private final String clientId = 'xxxxxxxxx';
private final String clientSecret = 'xxxxxx';
String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret;
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setBody(reqbody);
request.setMethod('GET');
request.setEndpoint('http://xxxx/api/xx-xxx-xxxxxxx-api/v1.0/getEmplId?firstName=xxx&lastName=xxx&middleName=xx');
HttpResponse response = http.send(request);
if (response.getStatusCode() != 201) {
  System.debug('The status code returned was not expected: ' +
       response.getStatusCode() + ' ' + response.getStatus());
} else {
   System.debug(response.getBody());
}
I'm getting the following message - response|"System.HttpResponse[Status=Service Unavailable, StatusCode=503]".
I've added the site url in salesforce. 

Please let me what I'm doing wrong?!

Appreciate your help!

Thanks,
NSK
 
Best Answer chosen by NSK000
MagulanDuraipandianMagulanDuraipandian
The issue is not with Salesforce.

Check this - https://httpstatuses.com/503

The server where the API is hosted is having the issue. 

--
Magulan Duraipandian
www.infallibletechie.com

All Answers

MagulanDuraipandianMagulanDuraipandian
The issue is not with Salesforce.

Check this - https://httpstatuses.com/503

The server where the API is hosted is having the issue. 

--
Magulan Duraipandian
www.infallibletechie.com
This was selected as the best answer
NSK000NSK000
Thanks for your response Magulan.

Client id and client secret can be passed through request.setbody() ? My code above is correct ? 
MagulanDuraipandianMagulanDuraipandian
It should be on the setHeader method. Check https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_httprequest.htm
--
Magulan Duraipandian
www.infallibletechie.com