Postman, an environment designed for API development, allows users to test APIs, create and execute automated tests, monitor responses, and perform various other tasks. Utilizing a mail carrier analogy, one can envision a Salesforce administrator or developer using Postman to test API responses effectively. Now, let’s explore how to configure Postman for Salesforce Rest API testing.
To test the Salesforce Rest API, follow these three straightforward steps:
- Create a Connected App for OAuth.
- Obtain the Access Token using Postman.
- Use Postman to test the Salesforce Rest API.
Creating a Connected App for OAuth
Salesforce Connected Apps are third-party applications or services that interact with Salesforce APIs. During the OAuth 2.0 flow, connected apps use an authentication token to receive an access token. Based on the granted permissions, the access token allows the app to make API requests on behalf of a user or the connected app itself. To perform OAuth in Salesforce, you need to create a Connected App. Follow these steps to create a Connected App:
1)GotoSetup->AppManager->NewConnectedApp.
2) Then from the above screen click on Connect Apps then the New button. Then add all the required information like below.
Give the connected app name, and email. Enable the OAuth setting then pass the callback URL and select the OAuth scope you want to give for now we will be giving ‘full Access (full)’ then click the save button. Then click continue to get details.
3)Once the connected app is saved, it will generate the consumer key and secret. Click on the Manage Consumer Details button on the connected app page. It will ask for a verification code which will be sent by email. After verification, it will show consumer detail in another window.
Create a Postman request to get the access token
Now let us create a Postman request to get the access token. Open Postman and create a new POST request.
Authentication URL: https://login.salesforce.com/services/oauth2/token
In the params tab set the below details
grant_type: password
client_id: CONSUMER_KEY
client_secret: CONSUMER_SECRET
username: YOUR_SALESFORCE_USERNAME
password: YOUR_SALESFORCE_PASSWORD
Replace CONSUMER_KEY, CONSUMER_SECRET, YOUR_SALESFORCE_USERNAME, YOUR_SALESFORCE_PASSWORD, and YOUR_SALESFORCE_SECURITY_TOKEN with actual Salesforce credentials.
Using Postman to Test the Salesforce Rest API
To connect Postman with Salesforce using an access token, follow these steps:
Use a GET request with the following URL:
{{_endpoint}}/services/data/v{{version}}/query?q=SELECT+Id+FROM+Account+limit+1
In the Headers tab, fill in the following fields:
Authorization: Bearer <access_token>
Content-Type: application/json
So, this is the way to test RestApi using the Postman tool.