This is quite an old post but I have run into a similar issue with batch requests.
It fails when using Content-ID's along with Prefer: return=representation with the message:
Content-ID Reference: '$1' does not exist in the batch context
It works perfectly if I remove Prefer: return=representation - however I need this to get ID/lookup fields back.
I haven't been able to find any documentation regarding the two.
Does anyone know of a solution?
EG
--dwa_batch_86262503-77f0-41f6-8a69-3412c4c73e1f
Content-Type: multipart/mixed;boundary=changeset_6b0e18cc-bae8-4365-8348-1d4cc2dcc068
--changeset_6b0e18cc-bae8-4365-8348-1d4cc2dcc068
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1
PATCH https://.dynamics.com/api/data/v9.2/entity1 HTTP/1.1
Content-Type: application/json
Prefer: return=representation
{"data" : "here"}
--changeset_6b0e18cc-bae8-4365-8348-1d4cc2dcc068
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 100001
PATCH https://.dynamics.com/api/data/v9.2/entity2 HTTP/1.1
Content-Type: application/json
{"data" : "here"}
--changeset_6b0e18cc-bae8-4365-8348-1d4cc2dcc068--
--dwa_batch_86262503-77f0-41f6-8a69-3412c4c73e1f--