Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

OData - Cannot update data on page :-(

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi

Can anyone help me how to solve this problem, i am trying to update data on a page via ODataV4 in NAV 2017?

It works perfect when i get or create a new record via OData, but when i try to update data, then i get the following error:

    "code":"","message":"'MERGE' requests for 'Collection' are not supported by Microsoft Dynamics NAV OData web services."

When i read the documentation it should be possible by using:  PUT OR  MERGE

But i am getting the same error from using both commands.

I use the ETAG value that is provided from GET, by creating a JSON response;

{

""data"":""data to update"",

       ""ETag"" : ""32;SZQ1dwCRpzWnZSUFeUqPzD4tPQ7CnAAA6;8063650;""

}

Thanks on advance :-)

/Graves Kilsgaard

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    You need to include the etag as part of http header

    Key is: If-Match

    Value:  W/"'<your etag>'"

    Sample: W/"'36;JAAAAACLAQAAAAJ7BDEAMAA2ADYAAAAAAA==7;82198090;'"

  • Suggested answer
    RE: OData - Cannot update data on page :-(

    Hi Martin

    Ahhh - you are sort of right.

    The function started as a separate function, but from the Update-NAVODataRecord() function you can see that it is calculated this way in the final version:

    $ETag = (Get-NAVODataRecord -NAVUri $NAVUri -NAVWebService $NAVWebService -NAVSearchParm $NAVSearchParm -NAVCredentials $NAVCredentials).ETag

    Unfortunately we forgot to remove the test of the Get-NAVODataRecordETag in the example.

    You don't have any use for the function itself as it is just part of the update and remove functions.

    Also - I've spottet an error in the function New-NAVODataRestMethodHeader

    "$CustomerETag" should be just "$ETag"

    I'll update the blogpost with these changes. Thank you for your feed back.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    Hi Gert,

    Thanks for this nice Blogpost.

    Unfortunately the function Get-NAVODataRecordETag is missing in this example.

  • Suggested answer
    RE: OData - Cannot update data on page :-(

    Hi

    Graves is one of my friends, and he is currently on holiday, so I'm not sure he will se your message.

    Anyway, we worked together on this blog-post after he solved the issue.

    Unfortunately it is in Danish, but it is mainly powershell anyway.

    You can probably see the request and inner workings from the powershell example code (powershell making misc. webservice calls to NAV).

    blog.systemconnect.dk

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    Hi Graves,

    Currently i have the same problem.

    Can you post us your whole Request?

    Thanks

    Martin

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    Hi

    I hav now found the solution..

    The problem was that i had to include the ETag in the headder, with the If-Match parameter.

    # ----- Build new headder for update -----
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("accept","application/json")
    $headers.Add("If-Match",'W/"' + "'" + [uri]::EscapeDataString($JToken.ETag.ToString()) + "'" + '"') #Etag Value
    $headers.add("Content-Type","application/json; charset=utf-8")
    


    /Graves

  • dkatson Profile Picture
    dkatson 2,263 on at
    RE: OData - Cannot update data on page :-(

    Hi, try to replace UserPassword with Service Access Key for this user.... Just try, may be this could help, if not ... will think furher

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    Hi

    At the moment I use: UserPassword, but connection is fine, i can Create and Get data from the service.

    The problem i have is that i cannot get the request right to build an OData request that updates data with a PATCH.

    What I cannot figure out what it is i am missing when the service tells me:

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

    /Graves

  • Suggested answer
    dkatson Profile Picture
    dkatson 2,263 on at
    RE: OData - Cannot update data on page :-(

    Did you created User Web access key?

    See my blog about MS Flow, it also use OData

    community.dynamics.com/.../how-ms-flow-can-make-a-friendship-with-nav2017

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData - Cannot update data on page :-(

    Hi

    It is working perfect when i GET and POST, but it is the PATCH (UPDATE) statement i am having problems with :-(

    I get the following error in Google (postman) and powershell when i try to address the ODATA feed:

    Invoke-RestMethod : {"odata.error":{"code":"","message":{"lang":"en-US","value":"Could not validate the client concurrency token required by the service. Please provide a valid token in the client request."}}}


    I have worked with the assumption that it is the etag that i have wrong, but it looks right:
    I am sending a header that looks like this:

    Key          Value                                                          
    ---          -----                                                          
    accept       application/json                                               
    etag         "'36%3BJAAAAACLAQAAAAJ7BDEAMAAwADcAAAAAAA%3D%3D7%3B10073950%3B'"
    Content-Type application/json               


    And as body i send a json file with the changes i would like to change in my NAV Service:

    Invoke-RestMethod -Uri $NAVServiceURL -Method PATCH -Credential $NAVServiceUserCreds -ContentType "application/json" -Body $Dataupdate -Headers $headers

    think it is very weird :-/

    /Graves

                                    

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans