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
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.
I will open this up to the community in case they have something to add.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156