How to connect organization data service of dynamics crm with node.js application

1.9k Views Asked by At

How do I connect to the organization data service of Dynamics CRM with a node.js application?

I do not have web api in developer resource, so how to get data with organization data service?

dynamic crm version iamge ... developer resource image

2

There are 2 best solutions below

3
James Wood On

If you are using CRM 2016 or later Use the Microsoft Dynamics 365 Web API

The Web API, which is new for Microsoft Dynamics 365 (online & on-premises), provides a development experience that can be used across a wide variety of programming languages, platforms, and devices. The Web API implements the OData (Open Data Protocol), version 4.0, an OASIS standard for building and consuming RESTful APIs over rich data sources.

Because the Web API is built on open standards, we don’t provide assemblies for a specific developer experience. You can compose HTTP requests for specific operations or use third-party libraries to generate classes for whatever language or platform you want.

If you are using CRM 2015 or earlier use the Organization Service (aka SOAP endpoint).

Available since CRM 2011 the service provided a classic SOAP endpoint and is probably the most commonly used web service. This service provides access to the full range of 365 operations, and messages. For .Net developers the SDK provides a set of assemblies that mean using the service is simple with the complexities of the SOAP endpoint abstracted away. Non-.Net developers have a more challenging environment and they must communicate directly with the SOAP endpoint which is typically a far more complicated affair.

4
Arun Vinoth-Precog Tech - MVP On

Am sharing the github code sample from this blog.

This uses OrganizationData service from Node.js script to pull FullName of Contacts (ContactSet).

    // Set the headers for the call to CRM
    var headers = {
      'Authorization': 'Bearer ' + sess.access_token, //send the oauth access token to authenticate
      'Accept': 'application/json' //tell CRM to send json data back
    }

    //configure the CRM odata request
    var options = {
      host : crm_host,
      port : crm_port,
      path : '/XRMServices/2011/OrganizationData.svc/ContactSet?$select=FullName', //hardcoded to select just the contact name
      method : 'GET',
      rejectUnauthorized: false,//to allow for self-signed SSL certificates - use at your own risk!!!
      headers : headers //set in the previous step
    };
    
    var reqGet = https.request(options, function(resGet) {
      //should do something here if we get 'www-authenticate': 'Bearer error' response headers
      //console.log("headers: ", resGet.headers);
      
      resGet.on('data', function(d) {
        //console.info('raw response: ' + d);
        var json = JSON.parse(d);
        var records = json.d.results;
        
        //console.info('results: ' + JSON.stringify(records));
        for (var i in records) {   
          res.write(records[i].FullName + '<br />');
        }
        res.write('</body>');
        res.write('</html>');
        res.end();
      });
    });
    reqGet.end();
    
    //handle errors
    reqGet.on('error', function(e) {
      console.error(e);
    });