Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Web API Batch Transactions - Content-ID URI Variables Not Working

(0) ShareShare
ReportReport
Posted on by 5

My team is having some trouble using changeset variables in batch transactions, as described in the official MSDN documentation for Dynamics 365 Web API Batch requests. When we attempt to reference an entity that was created in a previous changeset request with a "Content-ID: 1" header and use $1 as the root of the next changeset request's target URI, it returns an error stating “Invalid URI: The format of the URI could not be determined.” Here is an example of such a request:

--batch_1

Content-Type: multipart/mixed; boundary=changeset_2

 

--changeset_2

Content-Type: application/http

Content-Transfer-Encoding: binary

Content-ID: 1

 

POST /api/data/v8.2/contacts HTTP/1.1

Content-Type: application/json

Prefer: return=representation

 

{

    "firstname": "TestFirst1",

    "lastname": "TestLast1",

    "emailaddress1": "str@ing.com",

    "gendercode": 1 

}

 

--changeset_2

Content-Type: application/http

Content-Transfer-Encoding: binary

Content-ID: 2

 

POST $1/lastname HTTP/1.1

Content-Type: application/json

Prefer: return=representation

 

{

    "value": "TestLast2"

}

--changeset_2--

 

--batch_1--

I haven't encountered anything online indicating that the format of the reference URI is incorrect, and the request works fine when it is hardcoded as "POST api/data/v8.2/contacts(<entity guid>)/lastname HTTP/1.1"

Strangely enough, I haven't encountered any examples online of anyone using this feature against CRM. Is it supported, or is the MSDN documentation incorrect?

*This post is locked for comments

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Web API Batch Transactions - Content-ID URI Variables Not Working

    Refer here - https://vjcity.blogspot.com/2020/08/batch-request-in-dynamic-365-crm-web-api.html

  • Sub Profile Picture
    Sub 15 on at
    RE: Web API Batch Transactions - Content-ID URI Variables Not Working

    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--

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,317 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans