Breaking News

Thank You for visiting us, This website changed to www.TechNaandi.com , please go here we will update more concepts for you as soon as possible

How to connect to Salesforce with Postman ?

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 setup postman to test your APIs. 

Setting up Salesforce 

First, we need to set up a connected app in our org. To do so, follow the steps below: 

1. In your Salesforce org, go to setup and search for the app. You'll have an option of apps under Build->Create as shown below



2. Click on apps and that will open a new page with Apps, Subtab Apps, and Connected Apps. You need to go to the Connected Apps section and click New. 


3. You'll see another page of the New Connected App as shown below.



4. In the form, enter Connected App NameAPI Name and Contact Email. I am using Test Postman as the connected app name; the API name is automatically populated as Test Postman and I have added my email id in the contact email field.  

5. You don't need to fill any other information, In the API (Enable OAuth Settings) section click on - Enable OAuth Settings checkbox. As you click on that, you'll see some more fields appear as shown below


6. Under the Selected OAuth Scopes section, choose Access and manage your data (API) and move it from the Available OAuth Scopes to the Selected OAuth Scopes section. 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. 


7. Click on Continue button and you'll be taken to the below page

< IMAGE >
8. As you can see in the above image, we've Consumer Key and Consumer Secret which is present in the API (Enable OAuth Settings) section. The consumer key will be visible to you directly and for the consumer secret click on Click to reveal link and it'll be displayed there.  

You've completed the Salesforce part and now it's time to move on to our postman stuff. 

Setting Up Postman 

To setup postman, follow the below steps.

1. Go to https://www.getpostman.com/apps and download postman for your operating system. Install it in your OS 

2. Once you've postman installed, open it and you'll have a screen as given below

< IMagE >

3. To connect with our Salesforce org, we've two options: - Authorization Code Flow and Username Password Flow. We're going to use Username Password flow now. 

 
4. The next step is to get the access token. If you're connecting with your developer org, use: - https://login.salesforce.com/services/oauth2/token as the URL to get the access token, however, if you're using a sandbox, you can use https://test.salesforce.com/services/oauth2/token as the token URL. 

 5. Set the request method to POST and in the body tab, you need to enter some values as shown below

<Image >

6. Make sure that the form-data radio button is selected. Now we need to add 5 key-value pairs as shown in the above image and given below

 
Key: - username | Value:- <your login username for org> 
Key: - password | Value:- < your orgs login password> 
Key: - grant_type | Value: - password 
Key: - client_id | Value: - <consumer key of your salesforce org's connected app> 
Key: - client_secret | Value: - <consumer secret of your salesforce org's connected app> 

Add all the values and click on Send, you may or may not see the output as shown in the above image. It says

{ 
    "error": "invalid_grant", 
    "error_description": "authentication failure" 
} 

In case if you got this error, you should give security token, if you have a security token, use that otherwise, to get a new security token, click on your username and click on My Settings. In the search bar on the left write: - reset and you'll see an option showing Reset My Security Token click on that. Click on the Reset Security Token button. Check your email now which is associated with your salesforce org and you'll get the new security token there. 

The security token is case sensitive, so copy that from your mail and append it along with your password in postman. For ex:- if your password is iamtiger and your token is 123123123 then in the password key of your postman request, the value should be your password concatenated with security token i.e. iamtiger123123123. Click on the Send button again and you'll have the response.


Post a Comment

1 Comments