Hi:
I'm having some troubles to call methods of Dynamics Web Api.
With Adal I get the token, works smoot
---------
function acquireToken(dynamicsWebApiCallback){
//a callback for adal-node
function adalCallback(error, token) {
if (!error){
//call DynamicsWebApi callback only when a token has been retrieved
tokenTemp=token.accessToken;
dynamicsWebApiCallback(token);
callback(null,tokenTemp);
}else{
console.log('Token has not been retrieved. Error: ' + error.stack);
callback(error,null);
}
}
//call a necessary function in adal-node object to get a token
adalContext.acquireTokenWithClientCredentials(resource, clientId, secret, adalCallback);
}
---------
But, after getting the token, I try WhoAmI function, and fail
---------
var dynamicsWebApi = new DynamicsWebApi({
webApiUrl: resource+'/api/data/v9.1/',
onTokenRefresh: acquireToken
});
//call any function
dynamicsWebApi.executeUnboundFunction("WhoAmI").then(function (response) {
console.log('Hello Dynamics 365! My id is: ' + response.UserId);
callback(null,tokenTemp);
}).catch(function(error){
console.log(error);
callback(error,null);
});
---------
ERROR:
{ code: '0x80072560',
message: 'The user is not a member of the organization.',
status: 403,
statusMessage: 'Forbidden',
headers: '[Object]' }
---------
I double checked directory tenant, client id, secret key. All it's ok.
Putting wrong params, I can't create token properly. So... It's ok
Any ideas?
Kind regards