How to Call Salesforce.com Rest APIs

Rest APIs are quite easy to use and my preferred way to get things done. This post outlines how you can enable your SFDC instance to accept REST calls, and demonstrates fetching the data using Postman.

Create a Connected App

Create a connected app that tells SFDC that a valid client will try to access the REST APIs.

Go to Setup | App Manager. Click on ‘New Connected App’.

Enter the following parameters:

  1. Connected App Name and API Name – whatever makes sense
  2. Contact Email – ditto
  3. Check OAuth Settings – we will use OAuth for authentication
  4. Update Callback URL to “https://login.salesforce.com”, or anything that catches your fancy
  5. In “Selected OAuth Scopes”: select and add “Full Access”. Remember that this is for testing alone

salesforce connected app configuration

Save, and wait for 2-10 min as instructed. Make a note of the ‘Consumer Key’ (client_id) and ‘Consumer Secret’ (client_secret) when the process completes. (i.e., you no more see the instructional text on the page, and both the above fields are populated).

Make REST API calls using Postman

Open Postman. Click ‘New Request’ in the opening screen, or click New | Request.

postman-create-new-request

We authenticate before doing anything else.

In ‘Authorization’ tab: select ‘Type’ as ‘OAuth2’. Click ‘Get New Access Token’. Enter following details:

  1. Grant Type: Password Credentials
  2. Access Token URL: https://login.salesforce.com/services/oauth2/token
  3. Username
  4. Password (password + Salesforce security token)
  5. Client Id: client_id noted earlier
  6. Client Secret: client_secret noted earlier
  7. Client Authentication: Send client credentials in body

Click Request Token to generate a new token. Postman shows a popup on successful token generation. Note the ‘Instance URL’ – this is your SFDC base URL e.g. https://crmcog-dev-ed.my.salesforce.com. Click on Use Token once the token is generated to copy over the token to the main screen.

In the main screen, enter “instance_url” + parameters to do a ‘get’ operation. I just used a simple query – ‘SELECT ID, NAME FROM ACCOUNT LIMIT 10’.

Click ‘Send’ button to see the output.

postman sfdc rest api call results

Explore https://workbench.developerforce.com/restExplorer.php to know more about what you can do with REST services.

Leave a Reply

avatar
  Subscribe  
Notify of