Testing Salesforce REST APIs using Postman

What is Postman ?

Postman is a REST client for testing, debugging, monitoring and documenting APIs.

Is it free ?

There is a free version available with limited features and functionalities.

Compare pricing and versions here – https://www.getpostman.com/pricing

Setting up

Download and install Postman. When you run Postman for the first time, it will ask for an account, which can be created for free.

Postman is a powerful utility which consists of many different functionalities, but this article will describe only basic features.

Creating workspace

Workspace is a view for collections, environments, monitors … etc. They can be created for organising APIs of different projects or clients. There are two main types of workspaces available. Team workspaces can be shared with others, while Personal workspaces are visible only to you.

  1. Click the workspace drop down menu in the header bar. 
  2. Click the Create New link.
  3. Determine whether you’d like to create a personal or team workspace.
  4. If you creating Team workspace, you can add members by entering their email address or username of existing users. A personal workspace will be used in this tutorial. 

Creating collection

A collection is a logical grouping for requests. Within a collection, you can create folders to have sub-groupings.

  1. In the sidebar, select “Collections” and click the “Collections” tab.
  2. Click “+ New Collection” link to create a collection.

Other functionalities of using collections are described here.

Setting up environments

The environments are useful when you have to test endpoints in multiple Sandboxes/Orgs. It can hold key-value pairs, which can be utilize to hold different login credentials. By using environments, you don’t have to duplicate same endpoint to call against different sandboxes.

  1. Manage Environments icon
  2. Click Add button
  3. Insert variables as given in table below.
    Variable Initial Value Current Value
    base_url   BASE URL OF YOUR SANDBOX
    Eg: 
    https://ap15.salesforce.com
    username   SALESFORCE USER NAME
    password   SALESFORCE PASSWORD
    client_id   CONSUMER KEY IN YOUR CONNECTED APP
    client_secret   CONSUMER SECRET IN YOUR CONNECTED APP
  4. Next click “Persit All”
  5. Finally click “Add” and Select the environment you created from dropdown in right side corner.
  6. Similarly, you can add other orgs/sandboxes as environments.

Setting up authentication

Calling Salesforce REST API requires valid Oauth 2.0 token. Using Postman’s authentication it can be easily generated.

  1. Right Click on the Collection you created in previous step (or click View more actions icon) and click “Edit”.
  2. Goto “Authentication” tab.
  3. Select Type as “Oauth 2.0” and Add auth data to as “Request Headers”.
  4. Click “Get New Access Token” button.
  5. Enter any name for token. Eg : Salesforce Token and fill the form as below.
    Grant Type Password Credentials
    Access Token URL https://login.salesforce.com/services/oauth2/token
    Username {{username}}
    Password {{password}}
    Client ID {{client_id}}
    Client Secret {{client_secret}}
    Scope  
    Client Authentication Send client credentials in body
  6. For Sandboxes use token URL as below.
    https://test.salesforce.com/services/oauth2/token
  7. Click Get New Access Token, then it will generate new token.
  8. Next click “Use Token” button.
  9. Finally click “Update” button.

Calling REST API

  1. Right click on “Collection” and click “Add Request”.
  2. Enter a “Request name” and “Description”.
  3. Click “Save to Collection” button.
  4. Select the method (eg: GET) and enter endpoint URL after replacing base url with {{base_url}
  5. Set Authorization Type as “Inherit auth from parent”.
  6. Finally hit “Send” button to execute.

Leave a Reply

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