Skip to main content

Salesforce

How to Connect to Salesforce with Postman

Group of web developers working in an office.

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.

App Manager location

Step 2: You’ll see a page of the New Connected App as shown below:

New Connected App

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:

Enable Oauth Settings

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.

Connected App Submitted

Step 7: Click on the Continue button, and you’ll be redirected to the below page.

Manage Connected App

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.Verifictaion Code

Step 10: After successful verification, you will receive your consumer key and consumer secret.

Consumer Key

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.

Postman Screen

Step 3: If you are connected to through

Step 4: We must enter the URL and 5 required steps to get the Access Token of Salesforce Org.

Postman Parameters Error

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

Salesforce Profile

  • Select Reset my Security token

Reset Security Token

  • Click on Reset Security Token, then you will get such msg.

Reset My Security Token Salesforce

  • 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 :

Postman Parameters

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:

  1. 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.
  2. Select Get Method.
  3. 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.
  4. Click on the send button in response, and you will get the details of the record.

 

Creating a Record in Salesforce:

  1. 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.
  2. Select the Post method to create the record.
  3. Provide the Access Token, as we provided while retrieving data.
  4. Select the body section, select RAW, and provide the record details in XML or JSON format.
  5. Click on the send button.
  6. 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!

Thoughts on “How to Connect to Salesforce with Postman”

  1. Blog is very informative related to the integration. It will help beginners to understand about the Postman and Salesforce connection. Thanks Dimpy for sharing this knowledge.

  2. Ravinder Reddy Kambalapally

    I am using the Trail dev environment for the above setup: But getting this error: “The REST API is not enabled for this Organization.”

  3. Thanks for the post.
    If you don’t want to concatenate “password+token” (and if it does not work, even after concatenation), then try this:

    Enable this in SF: Identity-> OAuth and OpenID Connect Settings -> Allow OAuth Username-Password Flows
    – Allow your org to use the legacy OAuth 2.0 username-password flow to authorize an app that already has the user’s credentials.

    curl -v https://login.salesforce.com/services/oauth2/token -d “grant_type=password” -d “client_id=123456” -d “client_secret=abc123” -d “username=my.email.com” -d “password=MyPassword1”

    {“access_token”:”thisismyaccesstokenthatwasgenerated”,”instance_url”:”https://xyz-dev-ed.develop.my.salesforce.com”,”id”:”https://login.salesforce.com/id/abcdsdsaw/xyzabc”,”token_type”:”Bearer”,”issued_at”:”111122223333″,”signature”:”yyyydddddcccc/xxxccccvvvvv=”}

  4. Rakesh Keshri

    Amazing Post.

    But if you guys face this error

    {
    “error”: “invalid_grant”,
    “error_description”: “authentication failure”
    }

    Enable this setting: “OAuth and OpenID Connect Settings” in your org

    Just enable “Allow OAuth Username-Password Flow”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Dimpy Rangari

Dimpy Rangari is an Associate Technical Consultant at Perficient based out of Nagpur. She is a Salesforce Certified Administrator and Marketing Cloud Email Specialist. Dimpy is eager to learn and explore new technologies and is excited to share her Salesforce knowledge.

More from this Author

Follow Us