# Upsert an Account and Create a Contact

The following example uses the Composite resource to upsert an account and create a contact that is linked to the account. All these requests are executed in a single call. The composite.json file contains the composite request and subrequest data.

## Upsert an account and create a contact

```nolang
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/composite/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@composite.json"
```

## Request body composite.json file

```nolang
{
    "allOrNone" : true,
    "compositeRequest": [{
        "method": "PATCH",
        "url": "/services/data/v68.0/sobjects/Account/ExternalAcctId__c/ID12345",
        "referenceId": "NewAccount",
        "body": {
            "Name": "Acme"
        }
    },{
        "method" : "POST",
        "url" : "/services/data/v68.0/sobjects/Contact",
        "referenceId" : "newContact",
        "body" : {
            "LastName" : "Harrison",
            "AccountId" : "@{NewAccount.id}"
        }
    }]
}
```

## Response body after successfully executing the composite request

```nolang
{
    "compositeResponse" : [{
        "body" : {
            "id" : "0016g00000Wqu1EAAR",
            "success" : true,
            "errors" : [ ],
            "created" : true
        },
        "httpHeaders" : {
            "Location" : "/services/data/v68.0/sobjects/Account/0016g00000Wqu1EAAR"
        },
        "httpStatusCode" : 201,
        "referenceId" : "NewAccount"
    },{
        "body" : {
            "id" : "0036g00000WKnfLAAT",
            "success" : true,
            "errors" : [ ]
        },
        "httpHeaders" : {
            "Location" : "/services/data/v68.0/sobjects/Contact/0036g00000WKnfLAAT"
        },
        "httpStatusCode" : 201,
        "referenceId" : "newContact"
    }]
}
```

**See Also**

- [sObject Rows by External ID](/docs/platform/api-rest/guide/resources-sobject-upsert.md)
