10 Jul’17

D365 Business CentralProcedure to call an External API from Microsoft Dynamics NAV


In this article, I will be giving the procedure to call an External API from Microsoft Dynamics NAV. The external API which I am going to call from Microsoft Dynamics NAV is ‘Scribe Online’ as I want to perform real-time integration between Dynamics NAV and Dynamics CRM.


1. Microsoft Dynamics NAV
2. External API which will be called i.e. in this scenario, Scribe Online Mapping.


  1. JSON syntax will be used for storing and exchanging data from Microsoft Dynamics NAV.
  2. I have created the following variables:
    • StringBuilder’ of datatype: DotNet and Subtype: System.Text.StringBuilder.’mscorlib’
    • StringWriter’ of datatype: DotNet and Subtype: System.IO.StringWriter.’mscorlib’
    • String Reader’ of datatype: DotNet and Subtype: System.IO.StringReader.’mscorlib’
    • Json’ of datatype: DotNet and Subtype: System.String.’mscorlib, Version=, Culture=neutral, PublicKeyToken=***’
    • JsonTextWriter’ of datatype ‘DotNet’ and Subtype: Newtonsoft.Json.JsonTextWriter.’Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=***’
    • JsonTextReader’ of datatype ‘DotNet’ and subtype: Newtonsoft.Json.JsonTextReader.’Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=***’
  3. I have created a function ‘Initialize’ which upon calling will initialize StringBuilder, StringWriter and JsonTextWriter variables as below:
    StringBuilder := StringBuilder.StringBuilder;
    StringWriter := StringWriter.StringWriter(StringBuilder);
    JsonTextWriter := JsonTextWriter.JsonTextWriter(StringWriter);
  4. I have created a function ‘StartJson’ where I am calling the ‘Initialize’ variables function and then calling the ‘WriteStartObject’ of JsonTextWriter DotNet variable.
  5. Now create a function ‘AddToJson’ which accepts two parameters as below:

    The first parameter accepts the name of the Scribe field mapping   i.e. name of the External API field mapping.

    The second parameter is the field value which is passed from Microsoft Dynamics NAV.

  6. Create another function ‘EndJson’ and call the ‘WriteEndObject’ as below:
  7. Create a function ‘GetJson’ where the JSon content is converted ToString.
          JSon := StringBuilder.ToString;
  8. Next I have created a function ‘UploadJSon’ which will upload and POST the parameter values from Dynamics NAV.
    The UploadJson has the following parameters:

    The Subtype of DotNet variable ‘String’ is ‘System.String.’mscorlib, Version=, Culture=neutral, PublicKeyToken=***’

    WebServiceURL is the URL which will be called, in this case I will be passing the Scribe map URL which will be hit on a particular condition to perform real time integration.

    I have created two local variables for the UploadJson function as below:

    • HttpWebRequest’ variable of DotNet DataType and SubType : System.Net.HttpWebRequest.’System, Version=, Culture=neutral, PublicKeyToken=***’
    • HttpWebResponse’ variable of DotNet DataType and Subtype: System.Net.WebResponse.’System, Version=, Culture=neutral, PublicKeyToken=***’

    The following code is written in the UploadJson function:

    The CreateWebRequest, SetRequestStream, DoWebRequest and GetResponseStream functions are as below:

    The CreateWebRequest accepts two parameters from which the second parameter is the HTTP request method i.e. ‘POST’ or ‘GET’. I have used ‘POST’ as this method submits data to be processed by a specified resource.

    You can set the timeout required during which the External API should be called.

  9. Now in my codeunit’s OnRun() function I have written the following code so that the External API URL i.e. Scribe map is hit and the real time integration between NAV and CRM takes place.

    I am passing five field values from Dynamics NAV.

    Note: AddToJSon(‘Car_Stage’,CarStageGlobal) where ‘Car_Stage’ is the name of the Scribe field mapping and ‘CarStageGlobal’ is the NAV field value.

    I have passed the Scribe map URL to UploadJson function and the Json DotNet variable.


In this way, an External API can be called from Dynamics NAV. The External API URL i.e. Scribe map URL in this case is hit within seconds and real-time integration is performed quickly. The field values changed in Dynamics NAV are immediately reflected in Dynamics CRM.

Written by

Team Member


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Reading more then 10K records in D3FOE OData API

    11 July’ 2018

    Introduction: We all know Dynamics 365 Finance and Operations has limitation of 10K records to be fetched at a time usi...

    Read more
  • Paging in D365 Customer Engagement v9.0

    10 July’ 2018

    Introduction: The Xrm.retrieveMultipleRecords method is used to retrieve a collection of records in Dynamics 365 Custom...

    Read more
  • Set up Dynamics 365 connection in Microsoft Social Engagement

    10 July’ 2018

    Introduction: This blog explains how to Set up Dynamics 365 connection in Microsoft Social Engagement. Steps to be follo...

    Read more
  • Voice of the Customer failed to install

    10 July’ 2018

    Introduction: Many people face issues in installing Voice of Customer solution on v9 environment and trying repeatedly ...

    Read more
  • Scribe Insight AX as a Web Service Find Block issue

    10 July’ 2018

    Introduction: If we need to look up for any value from AX then we do it by using a Find Block in Scribe Insight Eg: Basi...

    Read more