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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans