10 Jul’17

Dynamics NAVProcedure 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

  • Dynamics 365 Client Diagnostics

    15 March’ 2018

    Main cause of Performance Issues: Bandwidth and latency are the primary characteristics which affects the performance o...

    Read more
  • Closing Blind Shift in MPOS and CPOS in Dynamics 365 for Retail

    15 March’ 2018

    Manual For closing Blind shift in POS: Blind shifts terminate the currently ongoing shift and when logged in a new shif...

    Read more
  • Persistent Filters in the Power BI Service

    13 March’ 2018

    Introduction: The feature is finally release, and it is power BI has announced general availability of persistent filt...

    Read more
  • Cause and Solution for Scribe MSMQ not receiving Message from AX

    10 March’ 2018

    Issue: Microsoft Message Queuing (MSMQ) service running on Server might be unable to receive messages. Therefore, messa...

    Read more
  • User Privileges on SharePoint – D365 Document Integration

    10 March’ 2018

    Overview: Often, we wonder what could be wrong where we see a generic error on Documents in Dynamics 365. Something lik...

    Read more