D365FO – Magic xpi: How to use DMF ImportFromPackage using REST API

5 import API has been provided by Microsoft to help customer to integration third part solution or data migration.

  • DataManagementDefinitionGroups-ImportFromPackage
  • DataManagementDefinitionGroups-ImportFromPackageAsync
  • DataManagementDefinitionGroups-ImportFromDMTPackage
  • DataManagementTemplates-ImportTemplateFromPackage
  • DataManagementTemplates-ImportTemplateFromPackageIgnoreMissingEntities

Goal : We are going to focus , in this article, on the Execution of an ImportFromPackage in D365FO with DMF REST API and check the result

1/ To start with import you need to create data project in D365

download package and grab manifest and Package header file to embed with data file to create new zip file.

2/ Check with postman the sequence to execute (GetAzureWriteURL=> Upload=>ImportPackacge=>GetStatus=>GetErrors)

3/ Define a REST Client Resource in the magic xpi project with informations below

Define 4 paths

/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetAzureWriteUrl

/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ImportFromPackage

/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionErrors

/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus

For each endpoint, you have to define Authorization in the header

4/ The Magic xpi flow starts with the authentification process (Get Token)

To get the token, you can check Steps 2,3 and 4 in the article (D365FO – Magicxpi How to use DMF ExportToPackage Method using REST API)

5/ After retrieving the token, do a POST to Get the Azure URL, use the REST Client Connector

Push the body in JSON format :

‘{“uniqueFileName”:”<zip file name>”}’

6/ Parse the JSON response to get the azure URL

Retrieve the JSON value content in a blob variable then parse this JSON to get the BlobUrl

Json response example :

7/ Load a zip file with data ,that you want to be pushed to D365FO, to a Blob variable

(Zip generation can be done with magic xpi, using Datamapper and FileArchive component.

Your zip file must contain PackageHeader.xml, Manifest.xml and your data file(s) (in our example, 2 csv files for sales header and sales detail)

Update an environment variable with the Azure URL.

8/ upload the zip file using an HTTP component

use a PUT to proceed, set theDataBlob to the ZIPFile blob variable

Set the header to : ‘Content-Type:application/zip,x-ms-version:2014-02-14,x-ms-blob-type:BlockBlob’

9/ use a REST Client Connector to call the import

Do a POST with content Type : application/json and security : Yes

The JSON body to push must be in the format :

example :

‘{
“packageUrl”:”https://ql1grpr93twb76.blob.core.windows.net/dmf/test.zip?sv=2014-02-14&sr=b&sig=qtnGxnvomjJ4fSq9ykaFI3D7%2FDOBMh8cqYrOOU6OJAI%3D&st=2023-03-02T15%3A53%3A50Z&se=2023-03-02T16%3A28%3A50Z&sp=rw”,
“definitionGroupId”:”test”,
“executionId”:””,
“execute”:false,
“overwrite”:false,
“legalEntityId”:”MSE”
}’

10 /Parse the JSON response to get the execution ID

11/ Build a JSON Request to get the status of the import

{“executionId”:”<executionid>”}’

12/ Use the REST CLIENT connector to get the Execution Summary Status

Set the DataBlob to the Json Body used in the previous step.

13/ Parse the JSON response to get the status

(*) Values for DMF Status are : Succeeded, PartiallySucceeded, Canceled, Executing, Failed, NotRun, Unknown

You can make a loop to ask for the status .

You can finish the process when Status is Succeeded, PartiallySucceeded, Canceled, or Failed

14/ if the status is PartiallySucceeded or Failed, you can retrieve the errors by doing a POST on

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut