Working with Salesforce REST API: Easy Steps, Key Types, Operations, and Limits

on API, Data Integration, REST API, Tutorials, Web APIs • October 22nd, 2021 • Write for Hevo

REST API is an API that follows a set of rules for an application and services to communicate with each other. As it is constrained to REST architecture, REST API is referred to as RESTful API. REST APIs provide a way of accessing web services in a flexible way without massive processing capabilities. Salesforce REST API is used in accessing Salesforce data without the use of the actual tool.

In this blog, you will understand the complete working of Salesforce REST API. The steps involved in setting up Salesforce REST API will be elaborated with examples. The types, operations, and limits of Salesforce REST API are also discussed in detail.

Table of contents

Introduction to Salesforce

Salesforce REST API: Salesforce logo
Image Source: Wikipedia

Salesforce is a cloud-based Customer Relationship Management (CRM) tool that is designed to support companies in managing their Sales and Customer related data. You can use the Salesforce CRM without any technical background as it is easy to set up and manage. It has redefined the relationship between businesses and their customers by developing a more meaningful connection between them. By providing a single view for each of your client interactions, Salesforce CRM can give you unique insights into the customer’s journey and at the same time empower you with tools that can enhance your customers’ experience.

Also, Salesforce is Cloud-based, which implies that it can provide high flexibility and scalability to its users. Salesforce is the ultimate solution for your business as it provides all the necessary elements for your business on an automation platform with embedded intelligence.

Introduction to Salesforce REST API

Salesforce REST API: Salesforce REST API  logo
Image Source: fiverr

Salesforce REST API gives you an option to access Salesforce data without the actual user interface. REST API Salesforce allows you to integrate Salesforce with other Apps and perform all the operations. Salesforce REST API provides a straightforward and sustainable interface with its RESTful architecture. REST API Salesforce tools allow you to create, manipulate and search for data in Salesforce. This is done by sending HTTP requests to endpoints in Salesforce.

With Salesforce REST API you can access and work with resources like records, query results, metadata and etc. The main reason for using REST API Salesforce is that it provides an ample amount of functions with fewer tooling requirements to access data from Salesforce.

Salesforce REST API access compatibility

The basic requirement to use REST API Salesforce to access Salesforce data is to have a Salesforce org with API access. And you will also require an API Enabled user permission within that org.

Salesforce provides API access with the following editions:

  • Professional Edition
  • Performance Edition
  • Enterprise Edition
  • Unlimited Edition
  • Developer Edition

The best practice while using REST API Salesforce is to perform all the testing and development in the Developer Edition, sandboxes, or scratch org. You can try and experiment with new things in a separate environment before actual implementation.

Before accessing the Salesforce REST API, you will need API Enabled Permission. This permission is provided by the administrator within an org. This permission is provided by default in the Developer Edition.

Simplify REST API ETL with Hevo’s No-code Data Pipeline

A fully managed No-code Data Pipeline platform like Hevo Data helps you integrate and load data from  100+ Data Sources (Including 40+ Free Data Sources) to a destination of your choice in real-time in an effortless manner. Hevo further provides a Native REST API Connector for free to help you load data from custom and non-native data sources to your desired destination without writing a single line of code.

Get Started with Hevo for Free

Hevo with its minimal learning curve can be set up in just a few minutes allowing the users to load data without having to compromise performance. Its strong integration with umpteenth sources allows users to bring in data of different kinds in a smooth fashion without having to code a single line. 

Check out some of the cool features of Hevo:

  • Completely Automated: The Hevo platform can be set up in just a few minutes and requires minimal maintenance.
  • Connectors: Hevo supports 100+ Integrations to SaaS platforms, files, databases, and BI tools. It supports various destinations including Amazon Redshift, Google BigQuery, Snowflake, and Firebolt Data Warehouses; Amazon S3 Data Lakes; and MySQL, SQL Server, TokuDB, DynamoDB, PostgreSQL databases to name a few.  
  • Real-Time Data Transfer: Hevo provides real-time data migration, so you can have analysis-ready data always.
  • 100% Complete & Accurate Data Transfer: Hevo’s robust infrastructure ensures reliable data transfer with zero data loss.
  • Scalable Infrastructure: Hevo has in-built integrations for 100+ sources that can help you scale your data infrastructure as required.
  • 24/7 Live Support: The Hevo team is available round the clock to extend exceptional support to you through chat, email, and support calls.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!

Salesforce REST API resources and requests

The REST API Salesforce depends on the resources. These resources include records, query results, metadata, or API information. You can access each resource by sending HTTP requests to the corresponding Uniform Resource Identifier (URI) of the resource. You will have to frame an HTTP request based on the resource you wish to access. The structure of the requests in REST API Salesforce consists of the following elements:

URI

Uniform Resource Identifier (URI) is the route to a resource in Salesforce. The basic structure of URI is the same while, each resource has its unique URI. The structured format of a URI is given below:

https://MyDomainName.my.salesforce.com/services/data/vXX.X/resource/

In the place of MyDomainName, add your Salesforce org’s subdomain. Replace vXX.X/ with your API’s version. Add your resource path in the place of resource.

HTTP method

REST API Salesforce supports HTTP request methods. These HTTP methods include the commands like HEAD, GET, POST, PATCH, PUT, and DELETE.

Headers are used to customize HTTP requests. REST API Salesforce supports standard as well as custom headers. But these custom headers must be related to Salesforce. Some of the most frequently used headers in REST API Salesforce include:

  • HTTP Content-type: This type of header points out the request body format attached with the request. For example, application/xml and application/json.
  • HTTP Accept: In this header type, it shows the client accepts format for the response body. The default value is application/json.
  • HTTP Authorization: This header type gives the OAuth 2.0 access token to authorize your client.
  • Compression header: This header type compresses the request.
  • Conditional request header: This header type verifies the records that access against a precondition.

Request body

The request body is a field in REST API Salesforce to add extra details to complete the request. The request body can be to add new records or field values to an existing record. A request body in REST API Salesforce can be in either JSON or XML format.

Salesforce REST API Compression headers

The purpose of a compression header is to compress a Salesforce REST API request or response. This compression header decreases the bandwidth used for a request. On the other hand, it demands a higher processing power at the client’s side. But bearing all this, the tradeoffs enhances the overall performance of your application.

Salesforce REST API supports these two compression algorithms based on HTTP 1.1 specification:

  • gzip compression algorithm
  • deflate compression algorithm

Request Compression

To compress a Salesforce REST API request, include a Content-Encoding: gzip or Content-Encoding: deflate header. However, the Salesforce REST API decompresses any request before processing.

This is a Salesforce REST API example request compressed with gzip.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/ -H "Authorization: Bearer access-token" -H "Content-Type: application/json" -H "Content-Encoding: gzip" —data-binary @new-account.json -X POST

Response Compression

If a request contains Accept-Encoding: gzip or Accept-Encoding: deflate header, then Salesforce compresses its response. Salesforce REST API is not required to compress any response as it does innately. If so it is compressed, the Salesforce REST API response will contain a Content-Encoding header with the compression algorithm. Now your client will decompress it.

This Salesforce REST API example request asks for a compressed response.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/0015e000009sS0DAAU -H "Authorization: Bearer access-token" -H "Content-Type: application/json" -H "Accept-Encoding: gzip" -X GET

Working with Salesforce REST API

Salesforce REST API Pre-requisites

You need to complete all the following pre-requisites before starting with Salesforce REST API. The Salesforce REST API Pre-requisites include:

Sign Up for Developer Edition

To get started with Salesforce REST API, sign up for Developer Edition. This Developer Edition is best suited to get started with testing and development. After signing up for Developer Editon, they’ll mail you the password information.

Ensure API Enabled Permission

Follow the instructions in User Permission given in Salesforce Help. Ensure to have API Enabled in your user profile.

Create a Connected App

You can create a Connected App, and configure the App according to your need. Before this, you need to configure basic connected App settings and enable the OAuth settings for API integration.

Acquire Consumer Key and Consumer Secret

To acquire the consumer key and consumer secret of the created connected App, follow these steps:

  1. Select App Manager from Setup.
  2. Select View from the dropdown menu of the connected App that you have created.
  3. In case the consumer key and consumer secrets are hidden, select Click to reveal and copy them.

Understand cURL

Since all the requests and responses of Salesforce REST API will be using cURL, it is really essential to understand its basics. Even if you don’t know it complete, familiarize yourself with cURL basics to understand the requests.

Salesforce REST API setting up authorization

The next step in Salesforce REST API is to set up authorization. The Salesforce REST API requires an access token to send requests. With the username-password authorization flow that can be used with cURL, you can get access to this token. When you use OAuth authorization flow, you need not add credentials in the request.

The following request template can be used to send requests to the Salesforce OAuth endpoints.

curl https://MyDomainName.my.salesforce.com/services/oauth2/token -d 'grant_type=password' -d 'client_id=consumer-key' -d 'client_secret=consumer-secret' -d 'username=my-login@domain.com' -d 'password=my-password'

Replace the following elements in the template as given below:

  • MyDomainName: Your Salesforce.org domain
  • consumer-key and consumer-secret: Your consumer key and consumer secret values that you’ve copied during the pre-requisites set up
  • my-login@domain.com : Your login id for your Salesforce org
  • my-password: Your login password

After your request becomes successful, you will receive the access token in the Salesforce REST API response.

Here is an example:

{"access_token":"00D5e000001N20Q!ASAAQEDBeG8bOwPu8NWGsvFwWNfqHOp5ZcjMpFsU6yEMxTKdBuRXNzSZ8xGVyAiY8xoy1KYkaadzRlA2F5Zd3JXqLVitOdNS",
 "instance_url":"https://MyDomainName.my.salesforce.com",
"id":"https://login.salesforce.com/id/00D5e000001N20QEAS/0055e000003E8ooAAC,
 "token_type":"Bearer",
 "issued_at":"1627237872637",
 "signature":"jmaZOgQyqUxFKAesVPsqVfAWxI62O+aH/mJhDrc8KvQ="}

Salesforce REST API Operations

Salesforce REST API can be used to perform the following Operations,

To get the Salesforce Version

The Salesforce REST API requests to see the available Salesforce versions.

curl https://MyDomainName.my.salesforce.com/services/data/

The corresponding Salesforce REST API example response with a header. This output has all the valid Salesforce versions.

Content-Length: 88 
Content-Type: application/json; 
charset=UTF-8 Server:
[
    {
        "label":"Spring '11",
        "url":"/services/data/v21.0",
        "version":"21.0"
    }
    ...
]

To get a list of resources

To get a list of resources, the following examples of Salesforce REST API requests can be used.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

Salesforce REST API response will give you the list of all the available resources.

{
    "sobjects" : "/services/data/v53.0/sobjects",
    "search" : "/services/data/v53.0/search",
    "query" : "/services/data/v53.0/query",
    "recent" : "/services/data/v53.0/recent"
}

To retrieve the list of available objects

To get a list of available objects, the following examples of Salesforce REST API requests can be used. You must submit a Describe Global request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

REST API Salesforce response will give you the list of all the available objects.

Transfer-Encoding: chunked 
Content-Type: application/json; 
charset=UTF-8 Server:
{
 "encoding" : "UTF-8",
 "maxBatchSize" : 200,
 "sobjects" : [ {
    "name" : "Account",
    "label" : "Account",
    "custom" : false,
    "keyPrefix" : "001",
    "updateable" : true,
    "searchable" : true,
    "labelPlural" : "Accounts",
    "layoutable" : true,
    "activateable" : false,
    "urls" : { "sobject" : "/services/data/v53.0/sobjects/Account",
    "describe" : "/services/data/v53.0/sobjects/Account/describe",
    "rowTemplate" : "/services/data/v53.0/sobjects/Account/{ID}" },
    "createable" : true,
    "customSetting" : false,
    "deletable" : true,
    "deprecatedAndHidden" : false,
    "feedEnabled" : false,
    "mergeable" : true,
    "queryable" : true,
    "replicateable" : true,
    "retrieveable" : true,
    "undeletable" : true,
    "triggerable" : true },
   },
...

To get basic object information

You need to submit a sObject Basic information request to get basic information of the metadata.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The basic features of the account object can be seen in the REST API Salesforce response.

{
    "objectDescribe" : 
    {  
        "name" : "Account",  
        "updateable" : true,  
        "label" : "Account",  
        "keyPrefix" : "001",  
        
        ...
        
        "replicateable" : true,  
        "retrieveable" : true,  
        "undeletable" : true,  
        "triggerable" : true
    },
    "recentItems" : 
    [ 
        {  
            "attributes" : 
            {    
                "type" : "Account",    
                "url" : "/services/data/v53.0/sobjects/Account/001D000000INjVeIAL"  
            },  
            "Id" : "001D000000INjVeIAL",  
            "Name" : "asdasdasd"
        }, 

        ...

    ]
}

To get a list of Fields

To get a list of fields, the following REST API request can be used. You can get more elaborate info on submitting a sObject Describe request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/describe/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The output response of this request is given below. The field attributes and child relationships of the account objects can be seen here.

{
    "name" : "Account",
    "fields" : 
    [
        {
            "length" : 18,
            "name" : "Id",
            "type" : "id",
            "defaultValue" : { "value" : null },
            "updateable" : false,
            "label" : "Account ID",
            ...
        },
        ...
    ],
    "updateable" : true,
    "label" : "Account",
    ...
    "urls" : 
    {  
        "uiEditTemplate" : "https://MyDomainName.my.salesforce.com/{ID}/e",  
        "sobject" : "/services/data/v53.0/sobjects/Account",  
        "uiDetailTemplate" : "https://MyDomainName.my.salesforce.com/{ID}",  
        "describe" : "/services/data/v53.0/sobjects/Account/describe",  
        "rowTemplate" : "/services/data/v53.0/sobjects/Account/{ID}",  
        "uiNewRecord" : "https://MyDomainName.my.salesforce.com/001/e"
    },
    "childRelationships" : 
    [ 
        {  
            "field" : "ParentId",  
            "deprecatedAndHidden" : false,  
            ...
        }, 
        ...
    ],
     
    "createable" : true,
    "customSetting" : false,
    ...
}

To execute a SOQL Query

After having all the Account objects, you can use the SOQL query to get the list of Account name values. For this, you need to submit a Query request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/query?q=SELECT+name+from+Account -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The output response consists of the Account name along with other attributes.

{
    "done" : true,
    "totalSize" : 14,
    "records" :
    [
        {
            "attributes" :
            {
                "type" : "Account",
                "url" : "/services/data/v53.0/sobjects/Account/001D000000IRFmaIAH"
            },
            "Name" : "Test 1"
        },
        {
            "attributes" :
            {
                "type" : "Account",
                "url" : "/services/data/v53.0/sobjects/Account/001D000000IomazIAB"
            },
            "Name" : "Test 2"
        },
        ...
    ]
}

To a field on a Record

You must submit a sObject request to update an attribute. To update an object, you need to first create a text file named patchaccount.json with the details that need to be updated.

{
    "BillingCity" : "Fremont"
}

The following request can be used to update a record.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/001D000000IroHJ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1" -H "Content-Type: application/json" --data-binary @patchaccount.json -X PATCH

In the response, you will have only the headers. Once you refresh the page, you’ll find the object being updated.

HTTP/1.1 204 No Content
Server: 
Content-Length: 0

Salesforce REST API Limits

REST API Salesforce request consists of two types of limits to ensure best of its performance. These two limits are:

Concurrent API Request Limits

The concurrent API request limits with 20 seconds or more duration are listed in the table below.

Org TypeLimit
Developer Edition and Trial orgs5
Production orgs and Sandboxes25
Table Source: Salesforce

Total API Request Allocation

The total API request limits with a24-hour duration are listed in the table below.

Salesforce EditionAPI Calls Per License Type Per 24-Hour PeriodTotal Calls Per 24-Hour Period
Developer EditionN/A15,000
Enterprise EditionProfessional Edition with API access enabledSalesforce: 1,000Salesforce Platform: 1,000Lightning Platform – One App: 200Customer Community: 0Customer Community Login: 0Customer Community Plus: 200Customer Community Plus

Login: 10External Identity 25,000 SKU: 70,000External Identity 250,000 SKU, 750,000External Identity 1,000,000 SKU: 4,000,000Partner Community: 200Partner Community

Login: 10Lightning Platform Starter: 200 per member for Enterprise Edition orgsLightning Platform Plus: 1000 per member for Enterprise Edition orgs
100,000 + (number of licenses x calls per license type) + purchased API Call Add-Ons
Unlimited EditionPerformance EditionSalesforce: 5,000Salesforce Platform: 5,000Lightning Platform – One App: 200Customer Community: 0Customer Community Login: 0Customer Community Plus: 200Customer Community Plus

Login: 10External Identity 25,000 SKU: 70,000External Identity 250,000 SKU, 750,000External Identity 1,000,000 SKU: 4,000,000Partner Community: 200Partner Community

Login: 10Lightning Platform Starter: 200 per member for Unlimited and Performance Edition orgsLightning Platform Plus: 5,000 per member for Unlimited and Performance Edition orgs
100,000 + (number of licenses x calls per license type) + purchased API Call Add-Ons
SandboxN/A5,000,000
Table Source: Salesforce

Conclusion

From this blog, you would completely understand the working of Salesforce REST API. The steps involved in setting up Salesforce REST API will be elaborated with examples that will be clear to you now. In addition, you would have also learnt about its types, operations, and limits.

Visit our Website to Explore Hevo

Hevo Data offers a faster way to move data from 100+ Data Sources such as REST API for free, into your Data Warehouse to be visualized in a BI tool. Hevo is fully automated and hence does not require you to code. Hevo provides a pre-built Native REST API Connector that will allow you to integrate data from a plethora of custom and non-native sources. All this without writing a single line of code and free of cost.

Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo suite first hand. You can also have a look at the unbeatable pricing that will help you choose the right plan for your business needs.

No-code Data Pipeline for REST API