Export Data with DMF DataPackage API's using Azure Logic apps

In this tutorial, we will guide you through the process of exporting data packages in Microsoft Dynamics 365. Please ensure your is generated before proceeding.

Data Package: Data Package is a simple .zip file that contains the source (import) or target data(export) itself . The zip file contains three files. The data file and the manifest files which contain metadata information of the Data Entity and the processing instructions for DMF.

The integration involves the following steps

  • Enable change tracking
  • Creation of the Data Export DMF Project
  • Authentication against Azure AD
  • Interact with DMF using REST API
  • Creation of Logic app to trigger the API

Pre-requisite :

1. Register an application in Azure AD and Grant access to D365FO. The detailed steps are described here. Instead of Dynamics CRM  select Dynamics ERP 

2. Register the AAD application in D365FO
  • System administration > Setup > Azure Active Directory applications
  • Click “New” -> Enter APP-ID(created as part of the previous step), Meaningful name and User ID (the permission you would like to assign).
  • The client application authenticates to the Azure AD token issuance endpoint and requests an access token.
  • The Azure AD token issuance endpoint issues the access token.
  • The access token is used to authenticate to the D365FO DMF and initiate DMF Job.
  • Data from the DMF is returned to the third-party application.
3. Authentication Details 
Http Method: POST
Request URL: https://login.microsoftonline.com//oauth2/token 
Parameters : grant_type: client_credentials [Specifies the requested grant type. In a Client Credentials Grant flow, the value must be client_credentials.]
client_id: Registered App ID of the AAD Application 
client_secret: Enter a key of the registered application in AAD.
Resource: Enter the URL of the D365FO Url (e.g. https://dev-d365-fo-ultdeabc5b35da4fe25devaos.clou
4. Interaction using REST API

The high level interaction of API calls to get the delta package via REST API is shown below.





 5. Now lets Implement this DataPackage API using a Logic app. lets take the example of                   CustomerGroups entity. So first thing we have to create a DMF data Project in Data Management     workspace. It looks as follows

6. Lets Implement a Logic app, As the flow looks exactly below















7. Now lets go through the Each step. 


  >>> in the step we are taking the variables called execution id and file name to store the values in further steps



8. Now lets take a Scope and add the HTTP trigger to call the ExportToPackage URL as Follows.

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage

BODY

{

    "definitionGroupId":"<Data project name>",

    "packageName":"<Name to use for downloaded file.>",

    "executionId":"<Execution Id if it is a rerun>",

    "reExecute":<bool>,

    "legalEntityId":"<Legal entity Id>"


It looks like below in Logic app













9. Note that the authentication will follows in below way in Logic app.














10. Now lets take a Do Until condition and call the execution status API to get the status. Auth will be Same as above API.











11. Take the True False condition to validate the status in above step.



12.  In the true condition use GetDataPackageURL it will return a URL with temp Blob storage location We can use this value and pass it to HTTP trigger in next step. We will get the Zip file stream as output





13. Upload the file to Azure blob storage. At this point we will get the .ZIP packaged file. 


 









14. In the next step, Take the Azure function to Unzip the Package file and return the CSV content file and load it to the output folder, 







 

15. So with the simple steps above we can export the data outside the D365 using DMF DataPackage APIs. I will explain the Function app creation and Publish part in my upcoming blogs.


Reference: https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/data-management-api


Thank you !!








No comments:

Post a Comment