Goal : Execute an export in D365FO with DMF REST API and save the result in a file locally.
Describe the different steps for connecting Magic xpi with D365 FO using Data Management Framework (DMF) API :

1/ Check that you get OAuth2 token from login.microsoftonline using Postman

(*) client_id, clientsecret, resource and tenantid are retrieve from azure portal (https://portal.azure.com)

(*) Check that client id is defined in D365 FO


2/ Create a REST Client Magic xpi resource to get the token (Project=>Settings=>Resources)

3/ Create a New Magic xpi Flow with a Flow Data Step. Update a blob variable with the desired credentials

4/ Use REST Client Connector to call Microsoft Online for getting the Bearer token.

and parse the json response to get the token using a Flow Data Component

5/ Set the JSON body to send for the export package using Flow Data Component
Json Body should be in this format
{
« definitionGroupId »: »<definitionGroupId> »,
« packageName »: »<packageName> »,
« executionId »: » »,
« reExecute »: « True »,
« legalEntityId »: » »
}

6/ Create a REST Client Magic xpi resource to call the export Package (Project=>Settings=>Resources)
Define 4 paths in other to work with DMF export :
- /DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage
- /DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus
- /DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl
- /DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionErrors

7/ Drag and Drop a REST Client Connector linked to the previous resource and configure the connector to call ExportToPackage method


8/ Set the body (DataBlob) with the previous JSON (step 5)

9/ Drag & Drop a DataMapper Component in other to retrieve the execution Id

10/ To get the status of the export package, create a json message using a Flow Data Component

11/ Drag and Drop a REST Client Connector and configure the connector to call GetExecutionSummaryStatus method
and pass the previous JSON message.


12/ Parse the json response to get the status using a DataMapper component

13/ Set a loop while Status is not ‘Succeeded’

14/ When Status is Succeeded, get the Url of the package and parse the JSON response to retrieve the url

15/ You can now use the url to download the package using an HTTP component.
URL should be in this format : https://<server>.blob.core.windows.net/temporary-file/<zipfilename>


16/ You can save the downloaded zip file using FileManagement component
17/ If the Status of the export Package is different than « Succeeded » then you can retrieve the errors using the method GetExecutionErrors

(*) Values for DMF Status are : Succeeded, PartiallySucceeded, Canceled, Executing, Failed, NotRun, Unknown
18/ Documentation reference
Merci pour cet excellent Article Saad. Au top