web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Problem connecting with Dynamics Web Api - Involuntary change URL

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Problem connecting with Dynamics Web Api - Involuntary change URL

    Hello,

    Can you share your code ?

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

    It's a custom integration:
    --------------------------------------

    exports.handler = function(context, event, callback) {

       var numTelefono = event.num;

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

       var resource = 'https://'+context.THE_ORG+'.crm4.dynamics.com';

       var destino = 'https://'+context.THE_ORG+'.crm4.dynamics.com/api/data/v9.1/';

      function acquireToken(dynamicsWebApiCallback){

          dynamicsWebApiCallback(event.token);

      }  

      //create DynamicsWebApi object

      var dynamicsWebApi = new DynamicsWebApi({

          webApiUrl: destino,

          onTokenRefresh: acquireToken

      });

      var request = {

          collection: "contacts",

          select: ["fullname", "firstname","lastname","emailaddress1","contactid","mobilephone"],

          filter: "mobilephone eq '"+ numTelefono+"'",

          maxPageSize: 5,

          count: true

      };

      //perform a multiple records retrieve operation

      dynamicsWebApi.retrieveMultipleRequest(request).then(function (response) {

          var count = response.oDataCount;

          var nextLink = response.oDataNextLink;

          var records = response.value;

          var recordCount = Object.keys(records).length;

          if (recordCount >=1){

              console.log(records[0].contactid);

              console.log(records[0].firstname);

              console.log(records[0].incidentID);

              var incidentID;

              var caseNumber;

              //Get incidentID

              var caseContact='contact('+records[0].contactid+')';

              console.log(caseContact);

              request = {

                  collection: "incidents",

                  select: ["ticketnumber,incidentid"],

                  filter: "_customerid_value eq "+records[0].contactid,

                  maxPageSize: 1,

                  count: true

              };

              //perform a multiple records retrieve operation

              dynamicsWebApi.retrieveMultipleRequest(request).then(function (response) {

                  var caseRecords = response.value;

                  var caseRecordCount = Object.keys(caseRecords).length;

                  if (caseRecordCount >=1){

                      incidentID = caseRecords[0].incidentid;

                      caseNumber= caseRecords[0].ticketnumber.substr(4);

                      console.log(caseNumber);

                      console.log('Found case');

                      //callback(null,{ticketNumber: caseRecords[0].ticketnumber, incidentid:caseRecords[0].incidentid} );

                      callback(null, {

                          contact_id: records[0].contactid,

                          first_name: records[0].firstname,

                          email: records[0].emailaddress1,

                          last_name: records[0].lastname,

                          phone: records[0].mobilephone,

                          CaseNumber: caseNumber,

                          incidentID: incidentID

                      });

                  }

                  else{

                      console.log('No case');

                      callback(null, {

                          contact_id: records[0].contactid,

                          first_name: records[0].firstname,

                          email: records[0].emailaddress1,

                          last_name: records[0].lastname,

                          phone: records[0].mobilephone,

                          CaseNumber: caseNumber,

                          incidentID: incidentID

                      });

                  }

              })

              .catch(function (error){

                  //catch an error

                  console.log(error);

                   console.log('Error no record 2');

                  callback(null,error);

              });

          }

          else{

              console.log('Error no record 1');

              callback(null,'Error');

          }

      })

      .catch(function (error){

          //catch an error

          console.log(error);

           console.log('Error no record at all');

          callback(null,'No Record');

      });

    };

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

    ____

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

    are you using adal to aquire your token ?

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

    Yes, I use Adal

  • meelamri Profile Picture
    13,216 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);

    });

  • Community Member Profile Picture
    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

  • Suggested answer
    meelamri Profile Picture
    13,216 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
    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

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

    Did you create an application user in your CRM ?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 242

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 83 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 68 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans