Sub topic 1
What the Salesforce REST API Is and When to Use It
Prerequisites
This chapter assumes you understand HTTP methods, headers, status codes, and JSON. You should also know basic Salesforce objects and record IDs. You need a Salesforce org and an OAuth access token.
Salesforce REST API
The Salesforce REST API is an HTTP interface for working with Salesforce data. A client sends requests to resource URLs. Salesforce returns status codes and JSON responses.
Use it when an application needs to create, read, update, or query records without using the Salesforce user interface. It is a good fit for integrations, scripts, web applications, and services that make occasional or moderate API calls.
Authenticating with an OAuth Access Token
OAuth 2.0 is an authorization standard. Salesforce issues an access token after an approved authentication flow. Send the token in the Authorization header:
curl "$SF_INSTANCE_URL/services/data/v60.0/sobjects/Account" \
-H "Authorization: Bearer $SF_ACCESS_TOKEN"Treat the token like a password. Store it in a protected secret store or environment variable. Do not commit it to source control or print it in logs.
Building Resource URLs
A resource URL combines the Salesforce instance URL, API version, and resource path:
https://instance/services/data/version/sobjects/ObjectName
For example:
https://example.my.salesforce.com/services/data/v60.0/sobjects/Account
The instance URL identifies the org. The version selects the REST API contract. The sObject name identifies the Salesforce object, such as Account or Contact.
Objects, Fields, and Record IDs
An sObject is a Salesforce data object. A record is one stored instance of that object. Fields hold record values, such as Account.Name or Account.Industry. Salesforce assigns each record a unique ID. Use that ID to address one record:
/services/data/v60.0/sobjects/Account/001xx000003DGb2AAG
Methods and Status Codes
| Operation | Method | Typical success status |
|---|---|---|
| Create a record | POST | 201 Created |
| Read a record | GET | 200 OK |
| Update a record | PATCH | 204 No Content |
| Delete a record | DELETE | 204 No Content |
A PATCH request sends only fields that should change. A successful update has no response body, so its status code confirms the operation.
Exercise
Which URL identifies one Account record in API version v60.0?
Show answer
/services/data/v60.0/sobjects/Account/{record-id}