Sunday, March 23, 2025

Export a Package from D365 Using the Rest API (ExportToPackage) and Upload It to Blob Storage Using Logic Apps

Export a Package from D365 Using the Rest API (ExportToPackage) and Upload It to Blob Storage Using Logic Apps


Follow the below steps:

1. Create an export project in DMF.

2. Use the ExportToPackage API URL listed below and pass the required parameters.
    URL:

{Resource}/data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage

   Input parameters:

  {
    "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>"
}

3. After triggering the ExportToPackage API, a record will be created in the job history, and the system will prepare a ZIP file.

4. The system will take some time to generate the package based on the data volume.

5. To handle this delay, use the until function and add a delay. Use the provided URL to check the status of the export job.

6. Assign the retrieved status to the Compose action.

   body('Get_the_execution_status')?['value']

7. The until loop will continue running until the status equals "Success."

8. After that, add a condition to check the status, and based on the result, proceed with downloading the file.

9. To download the file, trigger the API URL using the POST method and pass the executionId in the request body.

{Resource}/data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl


{"executionId":"<Execution Id>"}

10. Finally, upload the downloaded file to Blob Storage.


OutPut:


File uploaded to Blob:

 

  • We have passed the required parameters, and it is returning the execution ID.

  • We are passing the execution ID, and it is returning the status.

  • We are passing the execution ID, and it is returning the temporary blob URL.

  • We are assigning it to the blob, and it is being saved in the blob.






Keep Daxing!!

No comments:

Post a Comment