web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Javascript: Update invoice status using OData Rest API

(1) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,029 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,044 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,026 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans