Salesforce Rest API using cURL
cURL installation and setup guide
- First, download the cURL from the site, https://curl.haxx.se/download.html
- Select the OS version and download the file accordingly. For example, I have downloaded the 64 bit version for my windows 10, as mentioned in the below screenshot.
- Once after downloading the same, unzip the same and look for the folder where the “exe” file and a “certificate” resides.
- For example, in my machine, the two files located in the path as mentioned in below screenshots,
- Then please note down the complete path where both resides and we need to set the path to our System. For example, the complete path in my machine would look like this,
C:\Users\ryanamala\Downloads\curl-7.64.0_2-win64-mingw\curl-7.64.0-win64-mingw\bin
- Now, got to this path Control Panel→ System and Security→ System→ Advanced System Settings → A pop up window opens.
- Please select the Environment Variables button, Then we need to add the complete path which we copied earlier and add the same to the Variable named PATH.
- Look for PATH variable in both User variables and System Variables and edit the path variable to add a new location.
- Go to System Variables → Look for Path → Click Edit button → now a new popup window opens up → Click on New → Then an inline-editor opens → There we need to copy the complete path that we copied earlier.
- Follow the same process for the User Variables section as well.
- Please find the screenshot for your reference,
- Till now, we have configured the system variables and the path. Now, we can go to use the cURL from our machine.
- You need to install the cURL software, since its a open source application, we can use directly from our command prompt.
- Now look for the downloaded folder where the certificate is located. Then try to install the certificate in your machine.
- Locate the certificate first.
- Then, Right click on it and hit install this certificate.
- Select to install the certificate for local machine. Please find the screenshot for the same,
- Then click next → Hit yes for the “dll installation”.
- Then select the option “Automatically select the certificate store bases on the type of certificate”
- Click on Finish. That's it. The certificate got installed successfully.
- Now, we can test the cURL from our machine using the command prompt.
- Open the command prompt in your machine, and then type curl, then it will show the output as shown below
- Then type the command as “curl —help”, you will find so many commands as mentioned below,
- The cURL works like a web-browser. In order to test any URL, we can just append the curl in-front of that URL and hit enter.
Example:- curl www.google.com
By this way, we can test any URL like if we test in any API.
Business Scenario
We have an endpoint URL in our Salesforce and it is not working properly. And all our integrations are failing due to the incorrect endpoint.
Solution:-
- We just need to copy the endpoint URL that got configured in our Salesforce org and need to test the same in the command prompt using the simple command as mentioned in the above screenshot.
For example, this is my endpoint "https://callbackhunter.com/api/get_calls_data?id=1256&key=0f89bf53497f95f2f6556ea44e667007&date=2019-02-22>"
- Then I need to copy this and just type curl -vv -I -L and then paste this URL and hit enter.
C:\Users\ryanamala>curl -vv -I -L "https://callbackhunter.com/api/get_calls_data?id=1256&key=0f89bf53497f95f2f6556ea44e667007&date=2019-02-22>"
- Then we will get the response from that call as shown below,
> Host: callbackhunter.com
> User-Agent: curl/7.55.1
> Accept: / < HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx
Server: nginx
< Date: Fri, 15 Mar 2019 10:30:07 GMT
Date: Fri, 15 Mar 2019 10:30:07 GMT
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Connection: keep-alive
> User-Agent: curl/7.55.1
> Accept: / < HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx
Server: nginx
< Date: Fri, 15 Mar 2019 10:30:07 GMT
Date: Fri, 15 Mar 2019 10:30:07 GMT
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Connection: keep-alive
The above response depicts that our connection is alive. So the endpoint URL that we have tested is working fine and it is responding to our ping.
Comments
Post a Comment