Unexpected error
See original GitHub issueIssue Description
Hello
I am trying to run the basic example but i keep getting an unexpected error:
{ Error: Unexpected Error
at IncomingMessage.<anonymous> (/Users/araza/NodeScripts/CRM-scripts/node_modules/dynamics-web-api/lib/requests/http.js:82:33)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) status: 401 }
Here is my code… My client id and creds are correct because i tested by following the tutorial in this blog post:
Here is my code:
var DynamicsWebApi = require('dynamics-web-api');
var AuthenticationContext = require('adal-node').AuthenticationContext;
//the following settings should be taken from Azure for your application
//and stored in app settings file or in global variables
//OAuth Token Endpoint
var authorityUrl = 'https://login.windows.net<guid>/oauth2/token';
//CRM Organization URL
var resource = 'https://myorg.crm.dynamics.com';
//Dynamics 365 Client Id when registered in Azure
var clientId = '<my-client-id-here>';
var username = '<my-username>';
var password = '<my-password>';
var adalContext = new AuthenticationContext(authorityUrl);
//add a callback as a parameter for your function
function acquireToken(dynamicsWebApiCallback) {
//a callback for adal-node
function adalCallback(error, token) {
if (!error) {
//call DynamicsWebApi callback only when a token has been retrieved
dynamicsWebApiCallback(token);
} else {
console.log('Token has not been retrieved. Error: ' + error.stack);
}
}
//call a necessary function in adal-node object to get a token
console.log('calling auth')
adalContext.acquireTokenWithUsernamePassword(resource, username, password, clientId, adalCallback);
}
//create DynamicsWebApi object
var dynamicsWebApi = new DynamicsWebApi({
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v8.2/',
onTokenRefresh: acquireToken
});
//call any function
dynamicsWebApi.executeUnboundFunction("WhoAmI").then(function(response) {
console.log('Hello Dynamics 365! My id is: ' + response.UserId);
}).catch(function(error) {
console.log(error);
});
Please help. This package really looks promising and would love to use it on my project.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
"An Unexpected Error Occurred" Error Message When You ...
Cause. This issue may occur if there is low memory on the computer. As a result, the computer may lose the network bridge...
Read more >What Should I Do if I Get an “Unexpected Error” Message - uKit
If you encounter an unexpected error while editing your website in the uKit website builder, report the problem to the Support Team.
Read more >UnexpectedError
UnexpectedError.getErrorMessage(options). Returns the error message as a magicpen instance. The method uses the assertion error modes to produce the correct ...
Read more >An unexpected error occurred (I-200) - Adobe Support
Read this article to troubleshoot the error, "An unexpected error occurred", in Adobe Muse.
Read more >I received an "Unexpected error occurred" error message
Troubleshooting steps: First, try refreshing the page and signing the document again. We generally get that error when there is a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ended up solving it by creating an ‘Application User’ in Dynamics 365, using the Application (Client) ID listed on the App Service in Azure. Once I did that I got status 200. Thanks Alek.
@swhillance-mphn thanks for posting your solution.