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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

MS CRM Web API blocked by CORS policy

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

I am facing API blocked by CORS policy error when i trying to access data from my custom WEP API.

below code i am using for call wep API call.

var orgurl = "<web api url>";
var req = new XMLHttpRequest();
req.open("GET", encodeURI(orgurl), false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.setRequestHeader('Access-Control-Allow-Credentials', 'false');
req.setRequestHeader('Access-Control-Allow-Origin', '*');
req.setRequestHeader('Access-Control-Allow-Methods', '*');
req.setRequestHeader('Access-Control-Allow-Headers', "*");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
console.log("this.status: " + this.status);
if (this.status === 200) {
console.log("this.response: " + this.response);
var result = JSON.parse(this.response);
if (result.length > 0) {
for (var i = 0; i < result.length; i++) {
var obj = {};
obj.name = result[i].NAME;
console.log("obj: "+obj);
}
}
}
} else {
alert(this.statusText);
}
}
};
req.send();

below is error message:

Access to XMLHttpRequest at '<Web Api Url>' from origin 'https://<Org>.dynamics.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Above code is working fine if i am using chrome after disable-web-security.

using command  "chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security"

i have added CROS Origin allow settings in Web API C# config and controller files as well, still i am unable to get response from my Web API.

Please provide your suggestions. 

I have the same question (0)
  • priyatham Profile Picture
    15 on at

    Hi,

    Do you still have this issue?

  • Suggested answer
    bravoreddy Profile Picture
    67 on at

    When I had this issue and we realized this the vpn addresses has to be whitelisted for this api url for your CRM server.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans