What is Postman?
Postman is an API development environment that is used to test an API, create and run automated tests, examine responses and do a lot more stuff. As a Salesforce Developer or Admin, you can use Postman to test APIs and their responses. So, let’s see how to set up Postman with Salesforce org to test your APIs.
Setting Up Salesforce Org:
First, we need to set up a connected app in our org. To do so, we need to follow these steps:
Connected App is provided by Salesforce to connect with the platform from any other application.
Step 1: In Salesforce, go to the Quick Search bar and search for App manager and then click on New Connected App Button.
Step 2: You’ll see a page of the New Connected App as shown below:
Step 3: Now Fill in the Connected App Name, API name, And Contact.
Step 4: In the API (Enable OAuth Settings)section click on Enable OAuth Settings As you click on that, you’ll see some more fields appear as shown below:
This is quite similar to when we make a connected app at any 3rd party server, which is used for server-to-server communication, as we’re going to use postman, so the Callback URL doesn’t affect us. You can write any URL there. It is basically the URL where the authorization code will be sent in case of OAuth. I have used https://www.salesforce.com.
Step 5: Under the Selected OAuth Scopessection, choose Full access(full) and move it from the Available OAuth Scopes to the Selected OAuth Scopes It is basically a choice of which APIs you want to use like if you want to use chatter API, you need to add it to the Selected OAuth Scopes section and a similar approach for any other API.
Step 6: Leave other options as it is and click on Save. You’ll see the below screen.
Step 7: Click on the Continue button, and you’ll be redirected to the below page.
Step 8: In the above image you will find Consumer Key and Secret, you need to click on Manage Consumer Details, to have access on those details.
Step 9: As you click on Manage Consumer Details, you will receive a verification code on your registered mail.
Step 10: After successful verification, you will receive your consumer key and consumer secret.
You have successfully completed Salesforce Step, and now we’ll move on to the Postman setup.
PostMan Setup:
Step 1: Download and install the Postman.
Step 2: Once installation is completed, open it, and you’ll have a screen as given below.
Step 3: If you are connected to through
Developer org URL: https://login.salesforce.com/services/oauth2/token
Sandbox URL: https://test.salesforce.com/services/oauth2/token
Step 4: We must enter the URL and 5 required steps to get the Access Token of Salesforce Org.
Step 5: Set the request method to POST, and from the body tab selects form-data, where you need to pass 5 parameters.
Key: grant_type || Value: password;
Key: client_id || Value: Consumer key from your salesforce-connected app
Key: client_secret || Value: Consumer Secret from your salesforce-connected app
Key: username || Value: Org Username
Key: password || Value: Org Password
Step 6: Add all the values and click on Send; you may or may not see the output as shown in the above image. As:-
{
“error”: “invalid_grant”,
“error_description”: “authentication failure”
}
If you get a successful response, then you will get the Access_token, but if you get the above msg, you need to follow some more steps. To get a successful response, you need to append a security token after your password. If you have a security token, use that one, otherwise, you need to generate a new security token.
Follow the steps to get a new security token:
Click on your Username –> Settings
Select Reset my Security token
Click on Reset Security Token, then you will get such msg.
Check your email associated with Salesforce org; there, you will get the new security token. Security Token is case sensitive, so copy it from your mail and append it to your password in postman.
e.g. Password – cooldays, Security Token – winter20*************
so now your password will be cooldayswinter20*************
Step 7: Now Click on the send button, and you will get a successful msg as below :
Now you will get access_token, instance_url, Id, token_type, issued_at, and signature in the JSON format.
To Retrieve Data from Salesforce using Postman:
Sample URL: https://instanceurl/services/data/v25.0/sobjects/Objectname/Id
instanceUrl: In this, we have to give the instance Url we got from the token API in the last step.
Objectname: Provide the name of the object in this parameter.
ID: Id of the record we are trying to fetch.
Select Get Method.
To set the access token – copy the access token from the URL response we got in the last step Click on Authorization from the drop-down, select Bearer Token and paste the access_token in the available space.
Click on the send button in response, and you will get the details of the record.
Creating a Record in Salesforce:
SampleURL: https://instanceurl/services/data/v25.0/sobjects/Objectname
instanceUrl:- In this, we have to give the instance URL we got from the token API.
Objectname: In this, provide the name of the object we are trying to create a record of.
Select the Post method to create the record.
Provide the Access Token, as we provided while retrieving data.
Select the body section, select RAW, and provide the record details in XML or JSON format.
Click on the send button.
Go to Salesforce and find the new record you created from Postman.
Note: The Access_Token has validity; it expires in a few minutes. So in case if it expires, you need to follow the same steps to get a new access token.
Happy Learning!
Leave A Comment