In this post, we will learn about how to test Salesforce REST API using postman. How To Make A Salesforce REST API Call From Postman.
What is Postman?
Postman is an API collaboration platform used for APIs. Postman is an application used for API testing. It is an HTTP client that tests HTTP requests, utilizing a graphical user interface, through which we obtain different types of responses that need to be subsequently validated.
How to test Salesforce REST API using Postman?
Force.com platform supports powerful web services API for interaction with external apps and salesforce.com. For secured interaction with third-party apps, Salesforce enforces the authentication process. Like below image
Image from Salesforce document. Let’s see step by step process to test Salesforce REST API using Postman.
1. Create a Connected App for OAuth
To perform OAuth in salesforce, you must create a Connected App in salesforce. Follow the below step to create a connected App.
1) Click on Setup->Create->App
2) Then from the above screen click on Connect Apps then the New button. Then add all the required information like below
3) Now After creating the connected App we have the consumer key and consumer secret.
4) Click on Manage and then click on Edit Policy. Then change to “Admin Approved user are pre-authorized”. then click on Save.
5) Now from the profile select System admin and save it.
Learn about Salesforce OAuth 2.0 JWT Bearer flow here.
2. Setup Postman.
Postman has two options for working with its app: desktop and web.
2.2 Then Create a workspace from Workspaces menu.
2.3 Now Click on Create Collection button and give your project name
3. Get Access Token in Postman
There are two ways to get an Access token
- By OAuth Setting in POSTMAN (Wizard one)
- By Post Callout (Direct URL)
3.1 By OAuth Setting in POSTMAN (Wizard one)
- Now Select your Collection and click on Authentication Tab
- Select Type OAuth 2.0
- Then click on “Get Access Token“. Then provide all below detail.
- Then click on Request Token button. Then it will ask you to enter userName and password.
- Here we have Access Token. Then copy Instance_URL and click on Use Token
NOTE:- May be After trying to login you will get the below error “Failed: Not approved for access“
- OAuth Endpoints in Salesforce
- Authorization: https://login.salesforce.com/services/oauth2/authorize
- Token Request: https://login.salesforce.com/services/oauth2/token
4. Setup variable for postman project
Open the Variable tab from the collection and you can set your
version for API like the below screen
5. Test Salesforce Rest API using Postman
Click on Add a request link under your collection. To make a callout
- Then you need to set method and URL for API then click on send button
You can also use a variable in the URL which we set up in step 4.
I hope this will help to learn postman for Salesforce API testing.