Introduction about Postman:
Postman is a desktop/web application that lets you do call HTPP based APIs like REST, SOAP. It is like Salesforce Workbench. We can execute all Salesforce-related API. Compared to Postman application, Workbench has several limitations.
- Workbench doesn’t allow you to save your configuration, reuse it on multiple orgs or collaborate.
- We cannot switch to multiple environments in Workbench.
- In Postman, we can switch the environment and all variable values are updated to environment specific values.
- In Postman, we can set headers and parameters and use any content type and there is no file upload limit.
Salesforce Postman Collection:
The Salesforce API’s Postman Collection is a collection of requests to help developers use the Salesforce standard APIs by providing ready-to-use examples of requests with a template environment with variables and header presets. Following are the list of APIs which has more than 230+ request.
- Async Query
- Chatter (Connect)
- Einstein Prediction Service
Let’s get started with the Postman collection. Make sure that you have downloaded the latest Postman app. If not, click on this link. You can also use the Postman web app, but it takes a longer time to set up and requires CORS configuration in Salesforce org. Use a web app if you are facing installation issues on the Postman app. Make sure you have logged in. Without logging in, you cannot fork the APIs collection to your workspace.
Setting up Environment and Collection using Salesforce APIs:
Open Postman Desktop app. In the Search bar, type Salesforce. You may see a list of results below. Click on Salesforce APIs authored by the Salesforce Developers team.
Here, we will create fork two things from Salesforce APIs. One is Environments and another is Collections.
Environment tab contains the template for setting org credential, Secret Key, Org Id, Access Token, etc. We can create multiple org environments by duplicating the Salesforce APIs and switching it to perform API requests through Collection.
Provide a valid fork label name. Make sure you have selected the correct workspace if you have multiple workspaces in your local. Click the Fork Environment button.
The collections tab has a list of 230+ requests where we can perform an action using the predefined template of REST/SOAP API. Let fork the Salesforce collection. In the Search bar, select Public API Network and Type Salesforce, and choose Teams. Click Salesforce Developers.
This is the team providing the collection of APIs. As you can see, Salesforce Developers Team is providing three collections.
- Salesforce APIs
- Salesforce C360 APIs
- Salesforce Marketing Cloud.
Click on Salesforce APIs
Click on three dots in Salesforce APIs > Create a fork. This will create a copy of your workspace.
Provide fork label name for Collection. Make sure you have selected the same workspace which you have forked Environment earlier. Click the Fork Collection button.
Now, you have everything to get started. Let’s authorize the current environment with your desired Salesforce org.
In your workspace, Go to the Environments tab > Select three dots and click on Duplicate.
Setting Org Credential:
- Provide desired environment label name. This will be used to identify the org to be switched later.
- Provide instance URL. Remember to update the URL based on the instance you wish to login. If you are using playground/developer/production instance, set your URL to https://login.salesforce.com. If you are using a Sandbox, then set the URL to https://test.salesforce.com.
- Provide username of your org.
- Provide password of your org. If your org has security token, the you must provide along with password.
- Click the Save button.
Authorize your org credential in the PostMan app:
1. Go to Collection tab > Under Salesforce APIs, Click on Auth folder > Click on SOAP Login.
In the Body tab, you can see the environment variable is used here.
Let us click the Send button. Oops! You might face 500 server errors as a responsible state.
The reason for this error is you have not set your environment as Active yet. Go to the console to see the request body you sent recently.
If you see the console and check the Request body, username and password are empty.
Let us set the current environment as Active by clicking the Checkbox next to your environment label name. Click the Send button. Hurray! Now, you have successfully logged into your org. If you see the request body, username and password are appended from current environment variables.
Now, go to your environment. Have you wondered how the org id and access token have been updated to the environment variable automatically after successful login?
Here, another magic is done through the Tests tab. Once we get the successful response, we are setting the response variable to the environment variable. All this JS is available in predefined Salesforce APIs collection.
If you want to login through OAuth2.0, follow below steps:
1. Under Collections, Click Salesforce APIs > Authorization tab.
2. Provide the access token whichever you want to name it.
3. Click on Get New Access Token. You will be redirected to authorize as shown below. Click the Allow button to authorize.
4. After successful authorization, you will see the below message in the Postman app. Click the use token button.
You are now all set to perform SOAP and REST operations. Let us play querying account data.
Go to Collections tab > REST > QueryAll. Add query as shown below in Params tab and hit the Send button to get all account records which are limited to 50.
Here, the result is returned for the Account records.