Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Javascript: Update invoice status using OData Rest API

Posted on by 5

Hi, I'm trying to consume an ODataV4 Rest Api to update the metadata of an invoice but I always end up with a cors error.
Here is the code I am using:

var data = JSON.stringify({"Status": "0- null"});
var xhttp = new XMLHttpRequest();
xhttp.open("PATCH", "">mainURL/.../WS_Invoices('documentNumber')", true);
xhttp.withCredentials = true;
xhttp.setRequestHeader("If-Match" , "*");
xhttp.setRequestHeader("OData-MaxVersion", "4.0");
xhttp.setRequestHeader("OData-Version", "4.0");
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhttp.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
xhttp.send(data);
xhttp.onreadystatechange = function(){
if (xhttp.readyState === XMLHttpRequest.DONE) {
      if (xhttp.status === 200){
         console.log(xhttp.responseText);
      }
     else{
         console.log('There was a problem with the request.');
     }
}
};

PS: When I use the same code for the "GET" endpoint, it works perfectly.

PS: we are using NTLM authentication

PS: tha "PATCH" consuming works perfectly via postman

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: Javascript: Update invoice status using OData Rest API

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans