From July 9th till 13th we will be at #MSInspire. See you there!

Consuming REST APIs in Dynamics AX 2012

23 Jun 2014

Restful APIs are some of the most heavily used APIs in industry. They have become a good alternative for SOAP, COBRA and RPC. In this post we’ll look at the steps for consuming REST based APIs in Dynamics AX.

Dynamics AX provides great support for interacting with REST based APIs. We have a simple routine with which we can call different REST based APIs.Dynamics AX uses the System.Net namespace to call external APIs. The classes that are used to call the services are HttpWebRequest and HttpWebResponse.

Let’s look at a sample in which we’ll call a REST API with the HTTP GET Method


The following are the classes that will be used to get the data




System.IO.Stream stream;




System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();


Processing Of API Call

Now let’s jump to the code that will get the data from a REST based API.

//This line gives the user control to run unmanaged and managed code


// Create Object for adding headers

headers = new System.Net.WebHeaderCollection();


clrObj = System.Net.WebRequest::Create(‘’);

webReq = clrObj;

//Set Method Type



// Set Content type


// Add Authorization code

headers.Add(“Authorization”, “sdfgvczzxcbtyfrvb”);

//Add header to request


//Get Service Point

servicePt = webReq.get_ServicePoint();


//Gets the response object

webRes = webReq.GetResponse();

//Get Stream

stream = webRes.GetResponseStream();

streamRead = new System.IO.StreamReader(stream);



With the help of this code we can easily get the data stream from an external API. In m next post we’ll discuss the POST and PUT methods we can use for this.

ABOUT Folio3 Dynamics Services

As Dynamics AX experts we specialize in Dynamics AX development including Dynamics AX customization, integration, implementation and mobility solutions. If you have a Dynamics AX development requirement you would like to discuss or would like to know more about our Dynamics AX development services, please get in touch with us.


Kamil Mushtaq

Latest From Our Blog
Difference between Dynamics CRM and the Dynamic...
Record a Purchase Invoice In Dynamics AX
November 28, 2019
A lot of people tend to get confused between the Microsoft Dynamics CRM and the Dynamics AX CRM, Read our detailed comparison between dynamics crm ...
Read more
7 Ways Dynamics 365 Finance and Operations Boos...
dynamics 365 finance
November 9, 2018
Introduction Launched by Microsoft, Dynamics 365 ERP is one of the most effective for businesses today. It is perfect to save the time, effort and ...
Read more
The Ultimate Guide to Dynamics 365 HR Payroll P...
dynamics hr payroll
October 30, 2018
For any business, irrespective of its size, payroll processing is one of the most important functions. Payroll processing is a method through which...
Read more