Send Multiple Requests Using Composite
The requests in a composite call are called subrequests. All subrequests are executed in the context of the same user. In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later subrequests by using a JavaScript-like reference notation.
{
"compositeRequest" : [{
"method" : "POST",
"url" : "/services/data/v61.0/sobjects/Account",
"referenceId" : "refAccount",
"body" : { "Name" : "Sample Account" }
},{
"method" : "POST",
"url" : "/services/data/v61.0/sobjects/Contact",
"referenceId" : "refContact",
"body" : {
"LastName" : "Sample Contact",
"AccountId" : "@{refAccount.id}"
}
}]
}
You can specify whether an error in a subrequest causes the whole composite request to roll back or just the subrequests that depend on it. You can also specify headers for each subrequest.
- All sObject resources (/services/data/vXX.X/sobjects/), including sObject Rows by External ID and excluding sObject Blob Get
- The Query resource (/services/data/vXX.X/query/?q=soql)
- The QueryAll resource (/services/data/vXX.X/queryAll/?q=soql)
- The sObject Collections resource (/services/data/vXX.X/composite/sobjects). Available in API version 43.0 and later.
Syntax
- URI
- /services/data/vXX.X/composite
- Formats
- JSON
- HTTP method
- POST
- Authentication
- Authorization: Bearer token
- Parameters
- None required
- Request body
- Composite Request Body
- Response body
- Composite Response Body
Example
For examples of using the Composite resource, see Execute Dependent Requests in a Single API Call and Update an Account, Create a Contact, and Link Them with a Junction Object.