In this scenario we assume that the Company record we want to assign to the new customer already exists in Financials and we know the Company record ID.

To create a customer, we need to run several dependent requests in a single API call:

To do so, we’ll use a composite request. For more information, see Using Composite Resources.


To try out the steps in this section, install Postman and open the Postman collection we have prepared for you. In the collection, open the Create a customer request and replace variables with actual values.

Download Postman Open Postman Collection


Step 1: Create a POST request

Configure your application to send the following composite request:

POST https://{your_Salesforce_domain}/services/data/v44.0/composite

where


Step 2: Configure authorization

Make sure your request uses OAuth 2.0. Authorization data must be included in the request URL.


Step 3: Configure headers

Configure the request headers to include the following key-value pairs:

Key Value
Authorization Bearer {access_token}
Example:
Bearer 00D0N000000h6Yq!AR0AQObORnk9lCldrMydk1Y3cuyqpscqcU.T1xvoM1uWkWrr8MLu2ehJLKp7Mz3Qeu.eQGI13qlH_HfGEEMxV_J8FdI1TwdR
Content-Type application/json

Step 4: Add JSON payload

Add your JSON payload to the request body. For example:

{
"allOrNone" : true,
"compositeRequest" :
    [
        {
        "method" : "GET",
        "url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Dimension__c/s2cor__UID__c/Customer/?fields=Id",
        "referenceId" : "CustomerDimension"
        },
        {
        "method" : "GET",
        "url" : "/services/data/v44.0/sobjects/s2cor__Sage_COR_Company__c/a1E0N000007Q2T5UAK?fields=Id",
        "referenceId" : "Company"
        },
        {
        "method" : "POST",
        "url" : "/services/data/v44.0/sobjects/Account",
        "referenceId" : "NewAccount",
        "body" : {
            "Name" : "Example account 1"
            }
        },
        {
        "method" : "POST",
        "url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Tag__c",
        "referenceId" : "NewCustomerTag",
        "body" : { 
            "Name" : "Example customer tag 1",
            "s2cor__Account__c": "@{NewAccount.id}",
            "s2cor__Dimension__c": "@{CustomerDimension.Id}",
            "s2cor__Company__c" : "@{Company.Id}"
            }
        }
    ]
}

In this example payload:

NOTE: We use the referenceId parameter in the fourth request just because it must be present in each request that’s part of a composite request.


Step 5: Send your request

Send your request to create the customer.