Dynamics 365 integration projects can be diffcult. In this multipart series of blog posts, we are going to discuss on how to connect the NodeJS application to Microsoft Dynamics 365 application.
Problem Statement
IMPULZ team was doing a master data and sales integration between the third-party cloud POS solution and the Microsoft Dynamics 365 Finance and Supply chain management application. There were discrepancies in the sales numbers between the two systems which needs further investigation. Third-party system was on cloud and D365 data needs to be verified from the UAT instance.
Solution
Fetch the data from both the systems using the REST APIs and dump the data in a single analytical relational database which was a local SQL Server Express database in our case. Our team can now use the standard SQL queries to analyse the sales numbers mismatch.
Our Technology Stack
For this we have to develop a small command-line utility to fetch the data through API using a standard technologies like .Net, Python etc. Being a Microsoft partner, .Net should be the very obvious choice but instead we opted for NodeJS. Why? A simple reason is the simplicity of JavaScript when compared to C# and its ability to handle JSON objects seamlessly (for an obvious reason – after all JSON is JavaScript Object Notation).
To dump the database into a SQL Server database we have used the Sequelize as an ORM, again it is a simple, lightweight tool with excellent command-line tooling.
So this was our tech stack:
- Node – latest version as a JavaScript runtime outside the browser context.
- JavaScript
- AXIOS – Node popular package for the API calling.
- SQL Server – for storage.
- Sequelize – an ORM to dump the data into the local SQL Server Database.
My Two Cents!
One of the task was to do in this utility was to do an Azure authentication and when I compared the code to do this in C#, it was a like an hell of an object hierarchy we need to deal with. Yes same old ‘using’ and object encapsulation in multi-layer hierarchies.
In JS it was literally a single endpoint calling to generate the Azure token.
First you need to register an Azure client application
Microsoft Dynamics 365 Finance and Supply chain app being an Azure resource requires a client application to be registered first. Registering a client application is simple and requires similar steps like we did in one of our earlier blog post. The only steps which differ are:
- You don’t have to specify callback URL because we are using the Azure client credentials flow here.
- The API permissions required differs from our previous blog post. You have to search for ‘Dynamics ERP’ from the permissions list and then select one of the appropriate permission from the list under ‘Delegated permissions’. We had selected ‘AX.FullAccess’ in our case. It should be as restricted as possible due to security constraints.
3. Since it is a app-to-app calling that’s why you also need to create the client secret by clicking the following link as shown below. Copy the generated secret securely. This secret is needed to generate token from the Azure Active Directory.
Registering a user in Dynamics 365
In your Dynamics client, go to System AdministrationàSetupàAzure Active Directory applications. Add a new record and paste the client id/application id copied from the Azure portal. Give it a meaningful name and assign the user who is going to impersonate the calls coming from the app. More restrictive, the better it will be.
What’s Next?
You need to develop a Node app on your own – 😊. Just kidding! In the next blog post we are going to explain the code main components and optionally we are going to publish the code in a GitHub public repo. Until then, stay tuned!
Now some marketing stuff – if you in need of any help in your integration projects, struggling with the on-going implementation project, you are a Microsoft partner and looking for an experienced Dynamics 365 consultants or you just want to say ‘Hi’, reach us at info@impulztech.com or 630-540-6302 Mon-Fri between 9 am – 4 pm central time.