[SalesForce] compositeRequest Invalid reference specified. No value

I'm trying to execute the following compositeRequest but I'm getting the error.

{
  "allOrNone": true,
  "compositeRequest": [
    {
      "method": "GET",
      "url": "/services/data/v46.0/query/?q=SELECT+id,Name+FROM+Contact+WHERE+Email+=+'test@gmail.com'",
      "referenceId": "refContactData"
    },{
      "method": "PATCH",
      "url": "/services/data/v46.0/sobjects/Case/5005O000000s7XXXX",
      "referenceId": "refCase",
      "body": {
        "Subject":"test",
        "ContactId": "@{refContactData.records[0].id}"
      }
    }
  ]
}

Second is getting failed and it is throwing an error.

Error:

  {
            "body": [
                {
                    "errorCode": "PROCESSING_HALTED",
                    "message": "Invalid reference specified. No value for refContactData.records[0].id found in refContactData"
                }
            ],
            "httpHeaders": {},
            "httpStatusCode": 400,
            "referenceId": "refCase"
        }

Kindly please let me know If I have missed any componet.

Best Answer

You have a capitalization error:

@{refContactData.records[0].id}

In the response body to a Query REST call, each record contains a field called Id, not id:

  "records" : [ {
    "attributes" : {
      "type" : "Contact",
      "url" : "/services/data/v46.0/sobjects/Contact/0031R000025XXXXQAA"
    },
    "Id" : "0031R000025XXXXQAA"
  },

I was able to execute a composite request analogous to yours simply by using

@{refContactData.records[0].Id}