Newer Version Available

This content describes an older version of this product. View Latest

Using a Composite Graph

This example shows how to use a composite graph. It also demonstrates how one request can use more than one composite graph.
  • Regular composite requests allow you to execute a series of REST API requests in a single call. And you can use the output of one request as the input to a subsequent request.

  • Composite graphs extend regular composite requests by allowing you to assemble a more complicated and complete series of related objects and records.

  • Composite graphs also enable you to ensure that the steps in a given set of requests are either all completed or all not completed. If you use this option, you don’t have to check which requests were successful.

  • Regular composite requests have a limit of 25 subrequests. Composite graphs increase this limit to 500.

Create a request:

1curl -X POST curl https://MyDomainName.my.salesforce.com/services/data/v63.0/composite/graph -H "Authorization: Bearer token" -H "Content-Type: application/json" --data @data.json

where the file data.json contains the definition of the graphs. The general format for the request body is:

1{
2  "graphs": [
3    {
4      "graphId": "graphId",
5      "compositeRequest": [
6        compositeSubrequest,
7        compositeSubrequest,
8        ...
9      ]
10    },
11    {
12      "graphId": "graphId",
13      "compositeRequest": [
14        compositeSubrequest,
15        compositeSubrequest,
16        ...
17      ]
18    },
19    ...
20  ]
21}

where compositeSubrequest is a composite subrequest result.

For example, two composite graph requests each create an Account and then create related records:

1{
2    "graphs" : [
3        {
4            "graphId" : "1",
5            "compositeRequest" : [
6                {
7                    "url" : "/services/data/v63.0/sobjects/Account/",
8                    "body" : {
9                        "name" : "Cloudy Consulting"
10                    },
11                    "method" : "POST",
12                    "referenceId" : "reference_id_account_1"
13                },
14                {
15                    "url" : "/services/data/v63.0/sobjects/Contact/",
16                    "body" : {
17                        "FirstName" : "Nellie",
18                        "LastName" : "Cashman",
19                        "AccountId" : "@{reference_id_account_1.id}"
20                    },
21                    "method" : "POST",
22                    "referenceId" : "reference_id_contact_1"
23                },
24                {
25                    "url" : "/services/data/v63.0/sobjects/Opportunity/",
26                    "body" : {
27                        "CloseDate" : "2024-05-22",
28                        "StageName" : "Prospecting",
29                        "Name" : "Opportunity 1",
30                        "AccountId" : "@{reference_id_account_1.id}"
31                    },
32                    "method" : "POST",
33                    "referenceId" : "reference_id_opportunity_1"
34                }
35            ]
36        },
37        {
38            "graphId" : "2",
39            "compositeRequest" : [
40                {
41                    "url" : "/services/data/v63.0/sobjects/Account/",
42                    "body" : {
43                        "name" : "Easy Spaces"
44                    },
45                    "method" : "POST",
46                    "referenceId" : "reference_id_account_2"
47                },
48                {
49                    "url" : "/services/data/v63.0/sobjects/Contact/",
50                    "body" : {
51                        "FirstName" : "Charlie",
52                        "LastName" : "Dawson",
53                        "AccountId" : "@{reference_id_account_2.id}"
54                    },
55                    "method" : "POST",
56                    "referenceId" : "reference_id_contact_2"
57                }
58            ]
59        }
60    ]
61}

The response is:

1{
2   "graphs" : [
3      {
4         "graphId" : "1",
5         "graphResponse" : {
6            "compositeResponse" : [
7               {
8                  "body" : {
9                     "id" : "001R00000064wc7IAA",
10                     "success" : true,
11                     "errors" : [ ]
12                  },
13                  "httpHeaders" : {
14                     "Location" : "/services/data/v63.0/sobjects/Account/001R00000064wc7IAA"
15                  },
16                  "httpStatusCode" : 201,
17                  "referenceId" : "reference_id_account_1"
18               },
19               {
20                  "body" : {
21                     "id" : "003R000000DDMlTIAX",
22                     "success" : true,
23                     "errors" : [ ]
24                  },
25                  "httpHeaders" : {
26                     "Location" : "/services/data/v63.0/sobjects/Contact/003R000000DDMlTIAX"
27                  },
28                  "httpStatusCode" : 201,
29                  "referenceId" : "reference_id_contact_1"
30               },
31               {
32                  "body" : {
33                     "id" : "006R0000003FPYxIAO",
34                     "success" : true,
35                     "errors" : [ ]
36                  },
37                  "httpHeaders" : {
38                     "Location" : "/services/data/v63.0/sobjects/Opportunity/006R0000003FPYxIAO"
39                  },
40                  "httpStatusCode" : 201,
41                  "referenceId" : "reference_id_opportunity_1"
42               }
43            ]
44         },
45         "isSuccessful" : true
46      },
47      {
48         "graphId" : "2",
49         "graphResponse" : {
50            "compositeResponse" : [
51               {
52                  "body" : {
53                     "id" : "001R00000064wc8IAA",
54                     "success" : true,
55                     "errors" : [ ]
56                  },
57                  "httpHeaders" : {
58                     "Location" : "/services/data/v63.0/sobjects/Account/001R00000064wc8IAA"
59                  },
60                  "httpStatusCode" : 201,
61                  "referenceId" : "reference_id_account_2"
62               },
63               {
64                  "body" : {
65                     "id" : "003R000000DDMlUIAX",
66                     "success" : true,
67                     "errors" : [ ]
68                  },
69                  "httpHeaders" : {
70                     "Location" : "/services/data/v63.0/sobjects/Contact/003R000000DDMlUIAX"
71                  },
72                  "httpStatusCode" : 201,
73                  "referenceId" : "reference_id_contact_2"
74               }
75            ]
76         },
77         "isSuccessful" : true
78      }
79   ]
80}

For more information, see Using Composite Graphs.