Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Problem connecting with Dynamics Web Api - Involuntary change URL

Posted on by Microsoft Employee

Hello:

I'm having a trouble accesing to Dynamics 365 web Api with NodeJs.

I'm using this function to operate:

var dynamicsWebApi = new DynamicsWebApi({
       webApiUrl: [URL],
       onTokenRefresh: [MY_TOKEN]

});

The problem, the adress I use is:

desgrupohiberus.crm4.dynamics.com/api/data/v9.1

But, after call the method "retrieveMultipleRequest" I have a 403 and the adress is

desgrupohiberus.api.crm.dynamics.com

This adress not exists and I don't know why this chage, it's involuntary.

Any ideas?

Kind regards

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    I try putting a wrong Id client and I have an error message when I create the token

    Any ideas?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    Looks like, the problem is on Token generation

    var DynamicsWebApi = require('dynamics-web-api');

       var clientId = context.APPLICATION_CLIENT_ID;

       var AuthenticationContext = require('adal-node').AuthenticationContext;

       //OAuth Token Endpoint

       var authorityUrl = 'login.microsoftonline.com/.../token';

       //CRM Organization URL

       var resource = 'desgrupohiberus.crm4.dynamics.com';

       var secret = context.SECRET;

       var adalContext = new AuthenticationContext(authorityUrl);

       var tokenTemp='';

       //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

                   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);

       }

       var dynamicsWebApi = new DynamicsWebApi({

           webApiUrl: 'desgrupohiberus.crm4.dynamics.com/.../',

           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("FAIL!!!");

           console.log(error);

           callback(error,null);

       });

    -----------

    Answer:

    { code: '0x80072560',

     message: 'The user is not a member of the organization.',

     status: 403,

     statusMessage: 'Forbidden',

     headers: '[Object]' }

    ------------

    I double check clientId and secret

    I'm a little lost

    But... The most weird thing... The token it's ok

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    Can you please check if you fill all the field in the application user record? Specially,  Application ID (Client ID).

    Ref: ajitpatra.com/.../

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    I create the user, register the app, create a secret key, add the URL callback, that's ok, but, in any call I to to Dynamics Web Api, I see the same result

    ------------

    { Error: getaddrinfo ENOTFOUND desgrupohiberus.api.crm.dynamics.com desgrupohiberus.api.crm.dynamics.com:443

       at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)

     errno: 'ENOTFOUND',

     code: 'ENOTFOUND',

     syscall: 'getaddrinfo',

     hostname: 'desgrupohiberus.api.crm.dynamics.com',

     host: 'desgrupohiberus.api.crm.dynamics.com',

     port: 443 }

    ----------------

    { code: '0x80072560',

     message: 'The user is not a member of the organization.',

     status: 403,

     statusMessage: 'Forbidden',

     headers: '[Object]' }

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    ajitpatra.com/.../

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    Did you create an application user in your CRM ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    I can't understad the problem

    Complete info of error:

    code: '0x80072560',

     message: 'The user is not a member of the organization.',

     status: 403,

     statusMessage: 'Forbidden'

    But, i'm creating the token without problem

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    Hi,

    I'm not sure if it's related to URL issue. I recommend reviewing your registered application in Azure Active Directory. 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    In this case of (WhoAmI):

    ------------------

    message: 'The user is not a member of the organization.',

    status: 403,

    statusMessage: 'Forbidden'


    In case of (retrieveMultipleRequest):
    --------------------------

    Error: getaddrinfo ENOTFOUND desgrupohiberus.api.crm.dynamics.com

    errno: 'ENOTFOUND',

     code: 'ENOTFOUND',

     syscall: 'getaddrinfo',

     hostname: 'desgrupohiberus.api.crm.dynamics.com',

     host: 'desgrupohiberus.api.crm.dynamics.com',

     port: 443

    I asume, the URL is changing somehow

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    What do you get when you perform WhoAmI function:

    dynamicsWebApi.executeUnboundFunction("WhoAmI").then(function (response) {

       console.log('Hello Dynamics 365! My id is: ' + response.UserId);

    }).catch(function(error){

       console.log(error.message);

    });

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans