Skip to main content

Notifications

Announcements

No record found.

Business Central forum

Put/Patch operation failed for OData Web API in D365 BC

Posted on by Microsoft Employee

Hi,

Can somebody provide any help for updating the data using OData Web API in D365 BC

I am able to perform GET and POST operations on API but getting error while doing PUT or PATCH operation , getting below error :-

Could not validate the client concurrency token required by the service. Please provide a valid token in the client request.


Not able to understand what token is required while updating data .

any suggestion would be helpful.

Thanks

 

 

  • Harish Kumar R Profile Picture
    Harish Kumar R 15 on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    Thanks for this Information.

  • Verified answer
    RE: Put/Patch operation failed for OData Web API in D365 BC

    Hi All,

    I've resolved the issue by passing *

    PATCH operations requires the 'If-Match' header to be set, either with a retrieved ETag or with '*'.

  • RE: Put/Patch operation failed for OData Web API in D365 BC

    Hi,

    I added etag in the header and removed back slash but still getting an error as 

    {
        "error": {
            "code""Request_EntityChanged",
            "message""Another user has already changed the record.  CorrelationId:  64b74fd1-292b-49ba-aa90-e587ffb220fb."
        }
    }
    Odata etag is W/"JzQ0O09nbEFlWHdPSVFSYk50VjB5ZWhpcmRsTThkWHVXM2tvR0tCTmRkRU44dGc9MTswMDsn"
  • Verified answer
    GedasB Profile Picture
    GedasB 27 on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    in Postman

    Headers set

    Key: If-Match and value copied from GET call but removed backslash \ .

    For example it was:  W/\"JzQ0O1NJQ2NIWDRxb2NXdmthUng2QXpwZmczY01NcitBVHlwTXljZ0E0TEUxQU09MTswMDsn\" then correct is: W/"JzQ0O1hSaHUzWnYrSDZ5M3V2NEwvQUQ3RC9yYkNqaGpxYzJ2NmFsYS91elBJTzg9MTswMDsn"

    Body set raw, format JSON and fill in fields want to modify:

    {

      "displayName": "ATHENS Desk1"

    }

  • RE: Put/Patch operation failed for OData Web API in D365 BC

    Please share the procedure how to create patch request in Postman

  • GreatScott001 Profile Picture
    GreatScott001 115 on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    Okay so after a bunch of testing this works:

    "If-Match" : W/"JzQ0O0R5YW05MUZNVG5vSUxjcHI0ZmZPUXcvTEZLOFpwRmRQSTgxcXFJYjlBTDg9MTswMDsn"

    So remove the escape characters for the " (\") and it all works.

  • GreatScott001 Profile Picture
    GreatScott001 115 on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    Thank you for updating the post.  I appreciate the additional information.

    However I am using ODATAV4, and the "etag" is looks like this:

    "@odata.etag": "W/\"JzQ0O0R5YW05MUZNVG5vSUxjcHI0ZmZPUXcvTEZLOFpwRmRQSTgxcXFJYjlBTDg9MTswMDsn\""

    Which appears to be the base64 encode version of the etag in just ODATA.

    If you have any insight on this, it would be appreciated.

  • GreatScott001 Profile Picture
    GreatScott001 115 on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    Thanks for updating this.  I ran across the post and appreciate the additional information.

  • Verified answer
    DBTL Profile Picture
    DBTL on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    I realize this is an old post but as I got here and found it unhelpful, I thought I would expand the answer for others stumbling upon this.

    The concurrency token ion NAV is the ETag but you only use it when PATCHing. (MS Says MERGE but if you're testing in POSTMAN, use PATCH)
    POST doesn't need the token, as a POST would be a new record so you can't have an ETAG yet (next line makes this obvious).

    You get the ETag from performing a GET to get the existing row which will include the ETag at the bottom of the data. It will change each time the record is updated.

    It looks like this

    "ETag": "40;uhMAAAJ7/0MATgAxADMAOQAzADgAMQA3AAAAAAA=1;00;"

    Then you need to supply this in the HEADER when you PATCH, using an if-Match.

    Start by making a header called If-Match and in the value put W/ followed by double quotes

    W/""

    Then insert single quotes in to the double quotes

    W/"''"

    Then past the Etag Value without any quotes into the single quotes

    W/"'40;uhMAAAJ7/0MATgAxADMAOQAzADgAMQA3AAAAAAA=1;00;'"

    Your entire PATCH operation in Postman should have three headers

    PATCH server:port/.../webservicename('id to be updated')

    "Accept" : "application/json"
    "Content-Type" : "application/json"
    "If-Match" : W/"'40;uhMAAAJ7/0MATgAxADMAOQAzADgAMQA3AAAAAAA=1;00;'"

    If you get the ETag header wrong you will probably get 

    "Another user has already changed the record."

    This is good, it's working but you got the text of the tag slightly wrong or someone else updated the row first so your update need to refresh its data (do another GET). Keep trying.

    Get it working on postman and you should be able to transfer your knowledge to you app.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Put/Patch operation failed for OData Web API in D365 BC

    hi Guys,

    I was able to perform PUT operation on ODATA Web API by help of team member , i was missing one parameter that we have to set i.e IF-Match.

    Thanks

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans