Sub topic 1
REST API Refresher: Endpoints, Versions, and Authentication
This chapter reviews the parts of the Salesforce REST API that every composite request relies on. It covers the URL shape, the API version, and the bearer token. Later chapters assume you can read these parts without help.
Prerequisites
This chapter assumes you already know:
- Basic REST concepts: HTTP methods, status codes, and JSON bodies.
- Salesforce objects, fields, and 15- or 18-character record IDs.
- How to get an OAuth access token and an instance URL for a Salesforce org.
- Basic SOQL and the sObject endpoints, such as
/sobjects/Account.
The anatomy of a REST URL
Every Salesforce REST call goes to your org's instance URL. The path that follows names the API, the version, and the resource.
https://MyDomain.my.salesforce.com/services/data/v60.0/sobjects/Account/001xx000003DGb2AAG| Part | Example | Meaning |
|---|---|---|
| Instance URL | `https://MyDomain.my.salesforce.com` | The host for your org. It comes from the OAuth response. |
| API root | `/services/data` | The base path for the REST API. |
| Version | `/v60.0` | The API version. |
| Resource | `/sobjects/Account/001...` | The object type and record you act on. |
Composite resources sit under the same root. The main one is /services/data/v60.0/composite. The others are /composite/batch, /composite/tree/{sObject}, /composite/sobjects, and /composite/graph.
API versions
The version in the path fixes the behavior of that call. A request to v60.0 returns the fields and follows the rules that existed in that release. Newer versions can add fields or resources, and a resource may not exist in older versions.
You can list the versions your org supports with an unversioned request:
curl "$INSTANCE_URL/services/data/" \
-H "Authorization: Bearer $ACCESS_TOKEN"The response is a JSON array. Each entry has a version and a url.
Version numbers matter more in composite calls than in single calls. The outer request has a version in its path. Each subrequest also carries its own URL, and that URL contains a version. Keep them identical. Mixing versions inside one request makes results harder to reason about.
Authentication
The REST API accepts an OAuth 2.0 access token. You send it in the Authorization header with the Bearer scheme.
curl "$INSTANCE_URL/services/data/v60.0/sobjects/Account/describe" \
-H "Authorization: Bearer $ACCESS_TOKEN"Two values come out of an OAuth flow, and you need both:
access_token: the credential you send in the header.instance_url: the host you send the request to.
Sending a valid token to the wrong host fails, so always build URLs from the returned instance_url.
A composite request makes one HTTP call, so you authenticate once. Every subrequest runs as the same user, with that user's permissions. Field-level security, object permissions, and sharing rules apply to each subrequest. A subrequest can fail with a permission error while the others succeed.
Common errors at this level
Check these first when a call fails before any composite logic runs.
| Status | Typical cause | Fix |
|---|---|---|
| 401 | The token is expired or invalid. | Refresh the token or sign in again. |
| 403 | The user lacks API access, or a limit was reached. | Check the profile or permission set, and the org's API usage. |
| 404 | The URL path or version is wrong. | Compare the URL to the table above. |
| 415 | The `Content-Type` header is missing on a POST. | Send `Content-Type: application/json`. |
A request flow in one picture
With this model in place, the next chapter looks at why sending many operations in one such call saves time and API usage.
Exercise
A teammate's composite request returns 404, and the URL is $INSTANCE_URL/services/data/composite. What is wrong, and how do you fix it?
Show answer
The URL has no API version. The path must be /services/data/v60.0/composite (or another supported version). Adding the version segment fixes the 404.
Exercise
Your request uses a valid token but fails with 401. You built the host from a hard-coded login URL instead of the OAuth response. What should you use instead?
Show answer
Use the instance_url returned by the OAuth flow as the host. The token is valid for your org's instance, so sending it elsewhere fails.