API/Integration is commanly used to connect different Apps. We can Test Salesforce Rest API using Postman. In salesforce we have bunch of Standard API are available. We can also develop our own custom API. But what if we need to give demo to third party so they can consume our API. For this we can Test Salesforce Rest API using Postman. As Postman is common utility which we can easily configure. So today we will check step by step how we can use Postman to test Salesforce Rest API.
1. Create Connected App
For the REST API we need client credentials to use OAuth flow. Firstly, we need to create connected APP in Salesforce. So in setup > search for Apps > In App click on connected APP. In the next screen fill all required details.
Store the client credentials as we need them in next step.
2. Get Access Token in Postman
Now we will start the Authentication and Access Token Process in Postman. Postman provides us OOTB functionality to make Access Token request. Postman Also supports many other OAuth protocal including OAuth 1, OAuth2, AWS Auth, JWT etc.
So if you don’t have Postman installed, Download it from here. Once installed open the app and in the click the second subtab “Authorization”. In that tab Click on button “Get New Access Token”. It will open a popup
So in the popup fill these details:
- Token Name: Any suitable name (For example: SF Token)
- Grant Type: Authorization code
- Callback URL: Authorize using browser
- Auth URL: https://login.salesforce.com/services/oauth2/authorize ( If you have custom domain enabled then provide custom domain URL https://tushardev-dev-ed.my.salesforce.com/services/oauth2/authorize)
- Access Token URL: https://tushardev-dev-ed.my.salesforce.com/services/oauth2/token
- Client ID: Your Client ID
- Client Secret: Your Client Secret
- Scope: Optional leave blank
- State: Optional
- Client Authentication: Select Send Client Authentication in body and click on Request Token
Once Successful Auth is completed. You will get Access Token, request Token and other details. Click on use this token and now you are ready to make request.
3. Test Salesforce Rest API using Postman
As we know we have standard enpoints available. So we can make request to them to get details. You will find the list of some of the sample APIs here.
We don’t need to set Access Token as postman take care of it. If you get any error that Token is missing, make sure below setting is correct.



4. Test Custom Rest API using Postman
While the other steps remain same for testing. URLs are slightly changed for Standard and Custom API endpoints.
While in Standard API endpoint look like
https://tushardev-dev-ed.my.salesforce.com/services/data/
In Custom API endpoint it changed to
https://tushardev-dev-ed.my.salesforce.com/services/apexrest/APIEndpointName/
So for demo purpose I have used below class:
Sample Code
@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {
@HttpDelete
global static void doDelete() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account account = [SELECT Id FROM Account WHERE Id = :accountId];
delete account;
}
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
return result;
}
@HttpPost
global static String doPost(String name,
String phone, String website) {
Account account = new Account();
account.Name = name;
account.phone = phone;
account.website = website;
insert account;
return account.Id;
}
}
So now we are ready to make request from the postman tool. Firstly we will make a POST request to create Account record. Secondly we will make GET request to get details of created record.
You will notice how we append ID in URL in GET request. So now we are ready with our work and can share it with anyone so that they can consume our APIs.
Click on the code to preview the code as curl or many other supported languages so you can share sample in diff languages.



Test Class of Custom Rest Class
Below is the sample test class for our custom Rest Class:
@isTest
private class MyRestResourceTest {
private static testMethod void positiveTest() {
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
//Test POST API
req.requestURI = '/services/apexrest/Account'; //Request URL
req.httpMethod = 'POST';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
String recId = MyRestResource.dopost('Test','9887988798','https://newstechnologystuff.com');
system.assert(recId != null);
//Test GET API
req.requestURI = '/services/apexrest/Account/'+recId; //Request URL
req.httpMethod = 'GET';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
Account acc = MyRestResource.doGet();
system.assert(acc != null);
//Test DELETE API
req.requestURI = '/services/apexrest/Account/'+recId; //Request URL
req.httpMethod = 'GET';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
MyRestResource.doDelete();
system.assert([SELECT ID FROM Account].size() == 0);
}
}
So following some steps we are ready to share our API with the world. Do you have any question, let me know in comments. Happy Programming 🙂
Hi. Thanks for really nice guide.
I have a small challenge in Postman. Salesforce says that “Your call is authenticated”, while Postman complains “Authentication failed, check console” and there is nothing in console.
Any ideas?
you should be able to get some error. Check if your keys are correct and return url properly setup.
Very helpful and knowledgeable article on how we can use postman to execute REST API. I searched through web and have gone through multiple articles but nothing was as useful as this one.