How does the Composite API optimize performance by batching multiple REST requests into a single HTTP call?
Answer
Basics: Creating an Account, a Contact and an Opportunity through the plain REST API takes three HTTP calls, each with network latency and API overhead. A composite request combines them into one POST to /services/data/vXX.0/composite, which cuts latency and API usage.
How it works:
- Send
{"allOrNone": true, "compositeRequest": [...]}. - Each subrequest has
method,url,referenceIdand optionallybody. - Later subrequests use
@{referenceId.field}(for example@{newAccount.id}) to consume earlier output. - The response returns a
compositeResponsearray withhttpStatusCode,bodyandreferenceIdfor each.
Advanced / deep dive: Know the family:
- Composite: up to 25 subrequests, dependent via reference IDs; up to 5 can be queries.
- Composite Batch (
/composite/batch): up to 25 independent subrequests, no references or shared transaction. - sObject Tree (
/composite/tree/<sObject>): nested parent-child creation, up to 200 records. - sObject Collections: create, update, delete up to 200 records of one or mixed types in one call.
- Composite Graph (
/composite/graph): many subrequests organized into independent graphs, for larger dependent workloads (verify current size limits). Behavior ofallOrNone: when true, any failure rolls back the entire request and the others showPROCESSING_HALTED; when false, successes commit and only dependent subrequests fail. Governor limits and triggers run for the data operations as usual, and a composite request counts as one API call against the daily limit (verify exact accounting in current docs). For high volume, use Bulk API 2.0 instead.