0

I've tried to leverage the new Composite Graph API to delete records for which I only know the external Id.

I've tried 2 ways and both of which have failed

  • Method 1: In a single request: a subrequest to GET the record a subrequest to DELETE the record using {referenceId.Id} in the URL

    Result: Failed

  • Method 2: In a single request a subrequest to PATCH the record a subrequest to DELETE the record using {referenceId.Id} in the URL

    Result: Endpoint not supported in Composite Graph API: /v51.0/sobjects/Account/{AccountToDelete.Id}

Has anyone successfully done a delete using the Composite Graph API?

2 Answers 2

2

Actually, as @sfdxfox said, you should better prefer Composite API because Graph API provides an enhanced way to perform composite requests, that is, it serves other purposes (e.g. allows to assemble a more complicated and complete series of related objects and records). But if you still want to use Graph API to delete records by external id, you can make the following request:

POST https://{{instance_url}}/services/data/v50.0/composite/graph
Accept: application/json
Cache-Control: no-cache
Authorization: Bearer {{access_token}}
X-PrettyPrint: 1
Content-Type: application/json

{
  "graphs" : [
    {
      "graphId" : "1",
      "compositeRequest" : [
        {
          "url" : "/services/data/v50.0/sobjects/Account/External_Id_Field__c/externalIdValue",
          "method" : "DELETE",
          "referenceId": "ref1"
        }
      ]
    }
  ]
}

So in case if your external id field value is unique, you will get the next response:

{
  "graphs": [
    {
      "graphId": "1",
      "graphResponse": {
        "compositeResponse": [
          {
            "body": {
              "attributes": {
                "type": "Account",
                "url": "/services/data/v50.0/sobjects/Account/0011j00000yM0ReAAK"
              },
              "Id": "0011j00000yM0ReAAK",
              "ExternalId__c": "externalIdValue"
            },
            "httpHeaders": {
              "Last-Modified": "Thu, 28 Jan 2021 23:04:41 GMT"
            },
            "httpStatusCode": 200,
            "referenceId": "ref1"
          }
        ]
      },
      "isSuccessful": true
    }
  ]
}

If your external id field value is not unique you'll get a response with "httpStatusCode": 300. In this case you should retrieve the records ids by external id using standard REST API:

GET https://{{instance_url}}/services/data/v50.0/sobjects/Account/External_Id_Field__c/externalIdValue
Authorization: Bearer {{access_token}}

Response:

[
    "/services/data/v50.0/sobjects/Account/0011j00000yM0ReAAK",
    "/services/data/v50.0/sobjects/Account/0011j00000yM0RgAAK"
]

And then having the ids of found records delete them using sObject Collections endpoind:

DELETE https://{{instance_url}}/services/data/v50.0/composite/sobjects?ids=0011j00000yM0ReAAK,0011j00000yM0RgAAK
Accept: application/json
Authorization: Bearer {{access_token}}

However, I don't believe it is possible to do it in a single composite request with 2 subrequests.

NOTE. You can delete up to 200 records at a time

1

Use the Composite API, not the Graph API. The latter is used to insert and update related records. The first subsequent would be a get, the second the delete call.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .