node.jssoapsoap-clientmicrosoft-dynamicsnode-soap

Is it possible to access Microsoft Dynamics NAV Web service from NodeJS?


I am using node-soap lib to create a soap client. On NAV side, Credential Type is Windows. When I am trying to access NAV Soap Web Service from NodeJS, It is giving me Error:401 (Access Denied). Here is the code what I am using in my application.

var soap = require("soap");
var url = "http://<url>"; // This is accessible from browser.

soap.createClient(url, function (err, client) {
        if (err) { console.log(err); }
        else {
            console.log(client.describe());
        }
    });  

Solution

  • So I just went through this to integrate between our ERP software and NAV (actually known as Dynamics365 Business Central now) and figure I'll leave what I've done here to help people. So just FYI, I did this on NAV 14.0.

    var soap = require('soap');
    var url = 'http://localhost:7047/{INSTANCE}/WS/{COMPANY}/Codeunit/{CODEUNITNAME}';
    
    var security = new soap['NTLMSecurity']({
      username: NAVUSERNAME,
      password: NAVUSERPASSWORD,
      domain: DOMAIN',
      negotiate: true
    });
    
    const wsdl_headers = {}, wsdl_options = {};
    security.addHeaders(wsdl_headers);
    security.addOptions(wsdl_options);
    
    return soap.createClientAsync(url, { wsdl_headers, wsdl_options })
    .then( 
      (client) => {
        client.setSecurity(security) 
        return client;
      }
    ).then((client) => {
      return client.FunctionNameAsync({params});
    })

    This will authenticate both the wsdl request and the SOAP service you are trying to access. When I first tried this, I got the error Couldn't find NTLM in the message type2 comming from the server. This was because my installation of NAV had NTLM authentication OFF by default. I have no idea what authentication method it was expecting with this off. You can enable this through the server manager: enter image description here

    After that restart the instance and your authentication will hopefully work. Hope this helps someone else.