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 365 | Integration, Dataverse...
Answered

Problem connecting with Dynamics Web Api after getting the token (node.js)

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at
  • Community Member Profile Picture
    on at

    I will try, unfortunately, I don't have admin account to do that, so, I ask to system admin.

    Please, keep in touch.

    Kind regards.

  • Community Member Profile Picture
    on at

    After creating application user, works fine

    Thanks

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans