Consuming Dynamics AX 365FO Data entities using Web API (Part 3)

Hi Guys,

This is with the 3rd and final part of same demo, In this post we will see what is the code we need to write on wep api project to get the data from Dynamics ax 365. In this post we will be reading the purchase order data from Dynamics ax 365. In case if you have not read the previous two parts then follow these links

https://msdax.wordpress.com/2018/03/20/consuming-dynamics-ax-365fo-data-entities-using-web-api-part-1/

https://msdax.wordpress.com/2018/03/22/consuming-dynamics-ax-365fo-data-entities-using-web-api-part-2/

To start with, we need to add few dll references on Web api project. Please make sure Microsoft.OData.Client dll should be of same version what we have referenced in AuthenticationUtility and ODataUnity project(These projects are previously discussed in last blogs).

using Manage Nuget Package option we can install package for Microsoft.OData.Client

Now with the simple coding part, we need to reference following dll.

I have created this initConfiguration method to authenticate my call using Azure, GetAuthenticationHeader method is given on OAuthHelper class, we will pass true for web api projects.

Then i have created this fillOrder method to fill the list based on the query i have read from Dynamics ax 365 for purchase orders.

This is the main web api method for reading the purchase orders, i am reading top 50 for now.

After all this simple coding and all the configuration effort, when i click run on the project, i got this cool browser with my results of orders.

This is the result after all the effort,

Consuming Dynamics AX 365FO Data entities using Web API (Part 2)

In this part of blog we will discuss, how we can create App on Azure, which is mandatory for creating this integration, if you have not gone through my last blog about setting up projects for creating this integration then please go through that

Consuming Dynamics AX 365FO Data entities using Web API (Part 1)

Now to start this:

1. We need to login to https://portal.azure.com we need Azure subscription, without Azure subscription we can not do this integration with D365FO

2. We could also create Trial subscription for demo purpose
Create an Azure trial

Once we are logged in to Azure then we will have interface like this and we will do these steps for creating Web Api App on Azure.

We need to click Azure Active Directory on Left pane, and then click App registration on center pane

Click New Application registration
Fill out App name, type (Native or WebApi) and Url that could be http://localhost. Click create to create the App.
Once app is created, click settings for giving access. Also note down the Application Id, This will be used in the Web api project we will create for consuming the data entity.

Click Add on Required permission page and add Microsoft Dynamics ERP permission and Grant it also.

Create private Key also, this is needed form Web Api apps. Please take a note of this also, this will be used as ActiveDirectoryClientAppSecret key in you web api application project.
We also need to list this application inside dynamics ax 365, In system administration module> Setup > Azure Active Directory applications. We need to place the Application id on this form

This concludes the Azure configuration part and listing of App on Azure portal, in the next blog we will see how we can consume Odata entities inside Web api project and how to make this integration happen.

Thanks

Amir 🙂 Happy Daxing.

 

 

 

 

 

Consuming Dynamics AX 365FO Data entities using Web API (Part 1)

Object is to read data from Dynamics ax 365FO data entities using Web Api project.

This is first part of the blog series on consuming Data entities using Web api, in this blog i will be covering the configuration part of the projects

Step 1: Download Dynamics ax integration sample project from GITHUB
https://github.com/Microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples

 

Extract the project, you will see different samples.

Step 2: We will copy two projects AuthenticationUtility and ODataUtility and move to the new web api project we are going to create.

 

New project structure will look like this.

 

We also need to add the reference of dll of two projects  AuthenticationUtility and ODataUtility to our new projects.

There is a class ClientConfiguration in AuthenticationUtility project that is required a configuration change and requires to set following attribute from your Azure subscription.

UriString, UserName, Password, ActiveDirectoryResource, ActiveDirectoryTenant, ActiveDirectoryClientAppId, ActiveDirectoryClientAppSecret

In the next blogs i will be covering

  1. How to setup web api project app on Azure and what are we needed to setup the app in Azure.
  2. I will be covering code side also on which i will demonstrate how we can consume OData entity.

Thanks
Amir (Happy Daxing)

%d bloggers like this: