Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

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

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api after getting the token (node.js)

    After creating application user, works fine

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api after getting the token (node.js)

    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.

  • Verified answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Problem connecting with Dynamics Web Api after getting the token (node.js)

    Hi,

    Thank you for your query.

    Did you create the App User in Dynamics 365?

    Please see the following post:

    https://ajitpatra.com/2019/12/04/d365-the-user-is-not-a-member-of-the-organization-error-while-connecting-to-ce/

    https://docs.microsoft.com/en-us/power-platform/admin/create-users-assign-online-security-roles#create-an-application-user

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans