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)

HTTP Error 401 - Unauthorized: Access is denied when accessing ms dynamics crm API

(0) ShareShare
ReportReport
Posted on by

I am using javascript code to access dynamic CRM API but getting

HTTP Error 401 - Unauthorized: Access is denied

below is my 2 sample codes and both of them giving same error

1.

var createLead1 = function (contant) {
request({
url: 'mydomain.api.crm.dynamics.com/.../accounts',
method: 'POST',
json: {
Name: 'Test Nmae'
}
}, function (error, response, body) {
if (error || response.statusCode != 201) {
console.log(response.body);
console.log('statusCode:' + response.statusCode);

} else {
console.log('success' + response.statusCode)
}

});
}

2.

 var webLead = new Object(); 

webLead.name = 'Test Account';
var jsonwebLead = JSON.stringify(webLead);
var createwebLeadReq = new XMLHttpRequest();

createwebLeadReq.open("POST", "mydomain.api.crm.dynamics.com/.../accounts", true,"username", "password");
createwebLeadReq.setRequestHeader("Accept", "application/json");
createwebLeadReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

createwebLeadReq.onreadystatechange = function () {

if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
console.log('onreadystatechange1:' + createwebLeadReq.responseText)
}
else {
console.log('onreadystatechange2:' + createwebLeadReq.responseText)

}

};

createwebLeadReq.send(jsonwebLead);
console.log('end');


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Check the url

    mydomain.api.crm.dynamics.com/.../accounts

    it could be

    crm5 instead of crm

    Get it from

    Settings->Customize the System -> Developer Resource

    Instance Web API

    Service root URL

  • Community Member Profile Picture
    on at

    Hi,

    I checked the same location (Settings->Customize the System -> Developer Resource) and found URL

    mydomain.api.crm.dynamics.com/.../v8.2

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     you mentioned CRM 2011 in the "tags" to thise post.. Is it 365 or 2011?

     Also, are you making those calls from a CRM web resource or from a different web site?

     If you are making those calls from a CRM web resource, are you able to open exactly the same url in a separate browser tab?

     And, finally, did you try "GET" instead of "POST"?  

    msdn.microsoft.com/.../mt607871.aspx

  • Community Member Profile Picture
    on at

    I have also tried this but getting authentication error.

    Actually i want to add the lead data but not able to success.

  • Suggested answer
    Clem Profile Picture
    2,541 on at

    Are you in the context of the CRM when doing the request ?

    If not check this : community.dynamics.com/.../web-api-authentication-from-javascript to authenticate over the CRM and then you will be able to query it.

    Clément

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