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