Overview of REST API
Overview of REST API
4. Authentication
• OAuth 2.0: Common authentication method. You need to obtain an
access token to make API calls.
• Session ID: Alternatively, you can use the Salesforce session ID for
authentication when making API calls.
5. Usage Example in Salesforce REST API
Suppose you want to retrieve all the Accounts in your Salesforce instance:
• Endpoint:
https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Ac
count/
• HTTP Method: GET
• Authorization: Bearer Token (OAuth 2.0)
• Response: A list of accounts in JSON format.
Example Request:
https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/
{
"totalSize": 2,
"done": true,
"records": [
{
"attributes": {
"type": "Account",
"url": "/services/data/vXX.X/sobjects/Account/0015g00000Xzzy2AAB"
},
"Id": "0015g00000Xzzy2AAB",
"Name": "Acme Corporation",
"Industry": "Technology"
},
{
"attributes": {
"type": "Account",
"url": "/services/data/vXX.X/sobjects/Account/0015g00000XzzzzZZZ"
},
"Id": "0015g00000XzzzzZZZ",
"Name": "Beta Solutions",
"Industry": "Consulting"
}
]
}
8. Advantages
• Lightweight: REST API is less complex and doesn’t require a lot of
resources to implement.
• Stateless: Each request is independent and does not depend on
previous requests. This makes it scalable and efficient for external
integrations.
• JSON Format: JSON is easy to parse and use in modern web and
mobile apps.
• You can use LIMIT, WHERE, and ORDER BY clauses in your SOQL
queries for filtering and sorting records.
• This helps in retrieving large datasets by making multiple calls to the API.
GET /services/data/vXX.X/sobjects/Customer__c/
GET /services/data/vXX.X/sobjects/limits/
Accept: application/xml
21. Versioning of API
• Salesforce REST API is versioned, which means that you can
specify which version of the API you want to use. This ensures
compatibility as Salesforce makes updates or changes to the API.
• You can find the version of the API you're working with by
referencing /services/data/vXX.X/, where XX.X is the version number
(e.g., v54.0).
• It's important to stay updated on which API versions are deprecated
or no longer supported to ensure your integrations continue to work
smoothly.
My Points
• REST API is highly useful when you need real-time, small amounts of
data fetched or updated from Salesforce.
• Because it uses JSON and works over HTTP, it's simple to integrate
into almost any modern programming language or framework (like
Python, JavaScript, or Java).
• I suggest using REST API when you want to keep things simple and
efficient for client-side integrations.