You need to sign in to do that
Don't have an account?

How create a Rest Client in SF that make a Get from another system?
Hi,
I'm trying consume a Rest API of another system using apex, but I don't know how do that.
I'm reading and following the steps of the Trailhead (REST and SOAP Integration) but this is not clearly for me.
So my ideia is:
Consume Rest API from another system and make a GET request (Thats include the authentication of the another system).
I don't know which exactly code the apex accept, so I'm totaly lost.
if someone can help me, telling me the steps I need to do and some GET code for example that include authentication, will help me a lot.
Someone can help me with this issue?
Best Regards
Rafael
I'm trying consume a Rest API of another system using apex, but I don't know how do that.
I'm reading and following the steps of the Trailhead (REST and SOAP Integration) but this is not clearly for me.
So my ideia is:
Consume Rest API from another system and make a GET request (Thats include the authentication of the another system).
I don't know which exactly code the apex accept, so I'm totaly lost.
if someone can help me, telling me the steps I need to do and some GET code for example that include authentication, will help me a lot.
Someone can help me with this issue?
Best Regards
Rafael
The answer depends upon type of API you are trying to reach. For example,
You should understand the authentication process of the API you are trying to communicate. I would suggest, try using tools like POSTMAN or cURL (Postman is lot easier). It will allow you the test the API that you are trying to use.
See these good articles which will help you with the sample code,
http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/
http://cyukt.com/learn/salesforce-rest-api-callout-consume-external-rest-api/
Also, when you say "I'm trying consume a Rest API of another system using apex," , are you trying to establish connection between one Salesforce org to another Salesforce. If yes, try using Salesforce to Salesforce funtionality. Its easier way to establish connnection between two salesforce orgs. If you want to do that via Rest API, see below link -
http://salesforce.stackexchange.com/questions/25021/how-can-i-integrate-one-sfdc-org-to-another-sfdc-using-rest-api
http://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-named-credentials-in-just-5-lines-of-code/
Hope this helps! :)
Thanks for your help.
- The other System that I'm saying is ServiceNow, so the integration will be of the Salesforce and ServiceNow.
- I already consume the Rest API of ServiceNow in Postman and Java, and I did a GET and POST for test.
- But I need do the same thing in APEX. I don't know if all the code I did in Java works in APEX.
- I don't know if exist some doc that give me all the code that the APEX accept.(Some type of library of APEX).
- The authentication accept a type "BASIC AUTHeNTICATION".
I write this to be more especific of what I want, but I thing these two links that you sent to me will help me, if not I came back :)
Thanks again Saurabh
I`m glad it helped.
Also, keep in mind you below things,
1) You will need to parse your JSON response in Apex so that you can use it. You can use this tool which will generate an Apex class for you to parse your response. All you have to do is pass your JSON query and click on generate.
2) You will need to write test class for your Apex callouts. Use Apex HttpCalloutMock Interface to replicate behaviour of your Webservice API.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Hope this helps.
Please mark this as Best Answer if it helps you!
Can you post an example of GET?
The POST I did and works.
Hi All,
I need some help. I have received APIs from a company that has API Username and Password and other details in JSON format. I have to POST some data on their server from Salesforce and then, later on, GET the data into the Salesforce. I am not sure how to do it. Can you please help me?
I tried the above code but I am still confused.
Thank you
Regards,
Ankit