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 :
Microsoft Dynamics CRM (Archived)

Getting CORS error while calling Dynamics 365 Operations JSON-Based custom service using Javascript

(0) ShareShare
ReportReport
Posted on by

Hi,

I am developing a simple SPA application and trying to access a Dynamics 365 for Operations JSON-Based custom service. I am using ADAL.js library for authentication. The way for authentication i am following from This Dynamics Community thread.

But opportunity, after successfully getting the valid token, and calling my target api with acquired token, i am not able to call the API and getting CORS error.

PSB screenshot for the same

enter image description here

Below is my code sample:

    var req = new XMLHttpRequest()
   req.open("POST", organizationURI + "/api/services/ServiceGroup/Service/Operaton", true);

   //Set Bearer token
    req.setRequestHeader("Authorization", "Bearer " + token);
   req.setRequestHeader("Accept", "application/json");
   req.setRequestHeader("Content-Type", "application/json");

   req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
     req.onreadystatechange = null;
     if (this.status == 200) {
      var empData = JSON.parse(this.response).value;
      console.log(empData);
     }
     else {
      var error = JSON.parse(this.response).error;
      console.log(error.message);
      errorMessage.textContent = error.message;
     }
    }
   };
   req.send();

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    I am not sure , may be you are missing something , could you please validate your step with below reference  -

    debajmecrm.com/.../dynamics-crm-cross-origin-resource-sharing-external-application-cors

    msdn.microsoft.com/.../mt595799.aspx

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi Goutam,

    Not talking about Microsoft Dynamics ERP not CRM.

    I have one more question, does CORS by default enable in Dynamics? if it doesn't enable by default then what is the way to enable it? –

  • gdas Profile Picture
    50,091 Moderator on at

    Yes from dynamics CRM 2016 onwards it's support cors . You don't need to enable it.

  • Community Member Profile Picture
    on at

    I am asking about Dynamics ERP  not for CRM.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    I will suggest you to post your question to related forum to get you answer quickly:community.dynamics.com/.../759

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans