Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Generate Authorized Access token for D365 CRM using javascript

(0) ShareShare
ReportReport
Posted on by 5

Hello,

I want to generate authorized access token for D365 CRM online to perform an operation using java script.

I have tried some code for the same but it throws an error of Cross Origin in browser, also apply the headers by lots of searching related to it and for the cross origin i have passed all the header something like "Access-Control-Allow-Origin", "*"  in the request.

But it didn't work.

I got error as shown below,

pastedimage1576759864872v1.png

Here is the code which i have written,

        var data = new FormData();

        data.append("client_id", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX");

        data.append("grant_type", "client_credentials");

        data.append("resource", "abc@.crm8.dynamics.com");

        data.append("client_secret", "XXXXXXXXXXXXXXXXXXX");

        var xhr = new XMLHttpRequest();

        xhr.withCredentials = true;

        xhr.open("POST", "">login.microsoftonline.com/.../token",false);

        xhr.setRequestHeader("accept", "application/json");

        xhr.setRequestHeader("cache-control", "no-cache");

        xhr.setRequestHeader("Access-Control-Allow-Origin", "*");

        xhr.setRequestHeader("Access-Control-Allow-Credentials", true);

        xhr.setRequestHeader("Content-Type", "application/json");

        xhr.setRequestHeader("Access-Control-Allow-Methods" , "GET, POST, DELETE, PUT");

        xhr.setRequestHeader("Access-Control-Allow-Headers", "x-requested-with credentials");

        xhr.send(data);

        xhr.addEventListener("readystatechange", function () {

            if (this.readyState === 4) {

                console.log(this.responseText);

            }

        });

Please Help.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans