+ Start a Discussion
Shri RajShri Raj 

REST API Integration Issue. - System.HttpResponse[Status=Service Unavailable, StatusCode=503]

Hello All,

I will try to frame my question in short.

End Goal : REST API Integration from Salesforce to a InHouse Lead Management System(LMS2)

SUCCESS Through Chrome APP
1.  All i need to do is retrieve values from LMS2. When i tried to use the Chrome APP 'Advanced Rest Client' and have passed the appropriate URL and Content in XML/TEST format in the form of POST methoed I was able to retrieve the values from LMS2 database.
For EG : If i pass 92126 then i was able to get 'SAN DIEGO' which is correct.

Here is the link (https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US)for Advanced REST Client.


PROBLEM from Salesforce :

2) When i created this REST class in SAlesforce and tried invoking the End Point then its throwing this error.

System.HttpResponse[Status=Service Unavailable, StatusCode=503]

public with sharing class LmsRestApiIntegration {

//LmsRestApiIntegration.invokeRestAPI()
@future(callout = true)
public static void invokeRestAPI(){
String URL = 'http://pasquote-bfapp.tent.trt.ccc.pri/QuickQuoteWebSvc/QQWebSvc.asmx';
String xmlContent = '';
xmlContent = '<?xml version="1.0" encoding="utf-8"?>';
xmlContent = xmlContent + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
xmlContent = xmlContent + '<soap:Body>';
xmlContent = xmlContent + '<GetCityListFromZip xmlns="http://www.ccc.com/irv/quickquote/auto/2006/10/01">';
xmlContent = xmlContent + '<zipcode>92126</zipcode></GetCityListFromZip>';
xmlContent = xmlContent + '</GetCityListFromZip>';
xmlContent = xmlContent + ' </soap:Body>';
xmlContent = xmlContent + '</soap:Envelope>';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(xmlContent);
req.setHeader('content-type','text/xml');
req.setHeader('content-length', '0');
req.setEndpoint(URL);
req.setHeader('SoapAction', 'http://www.ccc.com//irv/quickquote/auto/2006/10/01/GetCityListFromZip');
req.setMethod('POST');
String response = '' ;
HttpResponse res = h.send(req);
response = res.getBody();

System.debug('Response :'+response);

}
}

Please guide.

Thank You
Shri
Best Answer chosen by Shri Raj
James LoghryJames Loghry
You would have to talk to your network engineers and have them whitelist a range of Salesforce IP ranges for you.  See the following document: http://help.salesforce.com/apex/HTViewSolution?id=000003652&language=en_US (http://help.salesforce.com/apex/HTViewSolution?id=000003652&language=en_US)

All Answers

James LoghryJames Loghry
Did you add "http://pasquote-bfapp.tent.trt.ccc.pri/QuickQuoteWebSvc/QQWebSvc.asmx" to your remote site settings? https://help.salesforce.com/apex/HTViewHelpDoc?id=configuring_remoteproxy.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=configuring_remoteproxy.htm&language=en)
Gigi.OchoaGigi.Ochoa
Did you verify the endpoint URL is typed correctly?  Can you verify the service is up and running?
James LoghryJames Loghry
Furthermore, I'd check that all your URLs and headers are correct in your class. Actually, it would be easier to throw them in a custom setting, so that you can change the values when you deploy to production.  For instance, it looks like your header has a typo with an extra slash after ccc.com: 
'http://www.ccc.com//irv/quickquote/auto/2006/10/01/GetCityListFromZip'
And this URL with three subdomains doesn't look right to me:

http://pasquote-bfapp.tent.trt.ccc.pri/QuickQuoteWebSvc/QQWebSvc.asmx

logontokartiklogontokartik
You have </GetCityListFromZip> listed twice? is that the issue? Also does your WS accept JSON? Its much easier that way.
Deepak Kumar ShyoranDeepak Kumar Shyoran
It seems that you are trying to call a service from salesforce (publicly hosted) to your local machine (which does not have any public existence). You can only make calls to public IPs from salesforce.
Shri RajShri Raj

So many answers in so much little time. Much Overwhelmed!!!

Hello James 
1. Yes i have added the site into the Remote site settings. But it only considers until here " http://pasquote-bfapp.tent.trt.ccc.pri"
2. This URL is correct since, I have passed the same through Chrome REST API extension. And it was working. http://pasquote-bfapp.tent.trt.ccc.pri/QuickQuoteWebSvc/QQWebSvc.asmx . Since i mentioned its an IN-House .Net Application, It cannot be invoked from an External Website directly. Since the Chrome Extension is a Plugin inside our Network, I have a feeling thats how it worked getting the response back. 
3. If i use the same Chrome Extension from my home without connecting through our Office network then it doesnt work. Therfore i think its out Network issues or the Enpoint Application which is not globally available. 

Hello Gigi,
1. Yes the End Point is typed 100% correctly. if i paste it in a webbrowser then I'm able to access the page. 

Hello Kartik, 
1. The WS only accepts text/xml format. Thats the reason I'm sending the xml content. 

Shri RajShri Raj
Hello Deepak, 

I also have a feeling that could be the issue. The End Point is not publically hosted. Now, How can a Endpoint be hosted only for Salesforce.com? And also, Before talking to the end point team i want to make sure that i have corrected myself on the Salesforce side.
Thanks
James LoghryJames Loghry
You would have to talk to your network engineers and have them whitelist a range of Salesforce IP ranges for you.  See the following document: http://help.salesforce.com/apex/HTViewSolution?id=000003652&language=en_US (http://help.salesforce.com/apex/HTViewSolution?id=000003652&language=en_US)
This was selected as the best answer
Shri RajShri Raj
Yes James. I have also got a confirmation that none of the Salesforce IPs are being blocked currently in our Network. I'm not sure where could be the issue. 
Shri RajShri Raj
Would it be possible to know from Which specific Salesforce IP address am i making this REST callout? 
Shri RajShri Raj
I wouldnt say my issue is fixed but i think its with the IP restrictions. I want to choose a 'Best Answer' based on the information provide by everyone since this post might be helpful for others as well. 

Thanks everyone again!
sony sonusony sonu
hi shri raj,,does your prblem solved,, i have a same similar problem in the salesforce rest api please 
sony sonusony sonu
https://developer.salesforce.com/forums/?id=9060G0000005bQ2QAI
Joshi BhavyaJoshi Bhavya
I am new to REST API. I have heard that we can build backend of any transaction and payment gateway using REST API. Is it true? I want to make a Payment Gateway for one of my site which is Techcortex (https://techcortex.com/) to sell affiliate products.
Mayur Patil 67Mayur Patil 67
It is most likely that you endpoint does not allow access from outside some ip range which you indicated by saying it's not public. Salesforce is a SaaS application hosted outside the domain that your service is on. In order for Salesforce to access that endpoint resource you need to whitelist Salesforce IP ranges, which can be found here.
Whitelisting allows Salesforce to access the resource. The only caveat is that because Salesforce is multi-tenant it means that any instance of Salesforce on the range that you whitelist would have access to your endpoint. If this is not ok, you might want to add some sort of header or sign the request to the call to that identifies your Salesforce instance uniquely from any other instance to validate that the call originated from your Salesforce org.
(I am linking to the article instead of pasting the IP ranges here because these may change in the future).

Thanks (https://www.hindishayariadda.com)
Mayur Patil 67Mayur Patil 67
Please let us know if the above answer is useful or not.
Thanks (https://wordifact.com/jobriya/)