D365FFO – AX – Data management package REST API

This topic describes the Data management framework’s package representational state transfer (REST) application programming interface (API). The package API lets you integrate by using data packages. The REST API can be used with both cloud deployments and on-premises deployments. For on-premises deployments, this functionality is currently available for Microsoft Dynamics 365 for Finance and Operations, Enterprise edition with platform update 12 (November 2017) (version 7.2), build 7.0.4709.41184, and later.

Although on-premises support has been added, API names haven’t been changed. Therefore, Microsoft can keep a single API set for both cloud deployments and on-premises deployments.

Choosing an integration API

Two APIs support file-based integration scenarios: the Data management framework’s package API and the recurring integrations API. Both APIs support both data import scenarios and data export scenarios. The following table describes the main decision points that you should consider when you’re trying to decide which API to use.

Decision pointRecurring integrations APIData management framework’s package API
SchedulingScheduling in Finance and Operations appsScheduling outside Finance and Operations apps
FormatFiles and data packagesOnly data packages
TransformationSupport for Extensible Stylesheet Language Transformations (XSLT) if the data file is in XML formatTransformations that are external to the system
Supported protocolsSOAP and RESTREST
Service typeCustom serviceOpen Data Protocol (OData) action
AvailabilityMicrosoft Dynamics Finance and Operations (February 2016) and later. Note: This is not supported with the on-premises version of Dynamics 365 Finance and Operations.Microsoft Dynamics 365 for Finance and Operations with platform update 5 (March 2017) and later

If you decide that the recurring integrations API meets your requirement better than the Data management framework’s package API, see Recurring integrations. The rest of this topic discusses the Data management framework’s package API.

Authorization

The Data management framework’s package API uses OAuth 2.0 to authorize access. The API must be called by using a valid OAuth access token. For more information about OAuth 2.0 and Microsoft Azure Active Directory (Azure AD), see Authorize access to web applications using OAuth 2.0 and Azure Active Directory. For on-premises deployments, Active Directory Federation Services (AD FS) is used for authorization.

 Note

When you use the Client Credentials Grant flow, the application maintains an access control list. You can find the access control list at System administration > Setup > Azure Active Directory applications. The Azure Active Directory applications page shows the approved client IDs and the user security mapping that should be enforced when the API is called by using the Client Credentials Grant flow.

For on-premises deployments, this list must have a valid client ID from AD FS. Additionally, for on-premises use, <baseurl> in the following examples must append /namespaces/AXSF when a connection is made.

Import APIs

The following APIs are used to import files (data packages).

GetImportStagingErrorFileUrl

The GetImportStagingErrorFileUrl API is used to get the URL of the error file containing the input records that failed at the source to the staging step of import for a single entity. An empty string is returned if no error file is generated.

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

Body
{
	"executionId":"<string>",
	"entityName":"<string>"
}

Successful Response:

HTTP/1.1 200 OK
{
	"@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
	"value":"<errorfileurl>"
}

Input parameters

ParameterDescription
string executionIdExecution ID of import. This is called as Job ID in the UI.
string entityNameName of the entity for which to get the error file.

Output parameters

ParameterDescription
string errorkeysfileurlThe URL of the error file. The return value is empty if an error file was not generated.

GenerateImportTargetErrorKeysFile

The GenerateImportTargetErrorKeysFile API is used to generate an error file containing the keys of the import records that failed at the staging to target step of import for a single entity.

If this API returns true, then use the GetImportTargetErrorKeysFileUrl API to get the URL of the generated error keys file.

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

Body

{
	"executionId":"<string>",
	"entityName":"<string>"
}

Successful Response:

HTTP/1.1 200 OK
{
	"@odata.context":"https://<baseurl>/data/$metadata#Edm.Boolean",
	"value": <errorsExist>
}

Input parameters

ParameterDescription
string executionIdExecution ID of import
string entityNameName of the entity for which to get the error file

Output parameters

ParameterDescription
Boolean errorsExisttrue if there are import errors; false if there are no errors

GetImportTargetErrorKeysFileUrl

The GetImportTargetErrorKeysFileUrl API is used to get the URL of the error file that contains the keys of the import records that failed at the staging-to-target step of import for a single entity.

If the error file is available, this API returns the URL. If the error file is still being generated, or if there is no error file, the API returns an empty string.

 Important

Before you call this API, call the GenerateImportTargetErrorKeysFile API to generate the error file. If the GenerateImportTargetErrorKeysFile API returns true, call this API in a loop until it returns a non-empty string. If the GenerateImportTargetErrorKeysFile API returns false, this API will always return an empty string, because there are no errors.

Pseudocode exampleC#Copy

errorsExist = GenerateImportTargetErrorKeysFile(executionId, entityName)

if (errorsExist)
{
    errorFileUrl = null

    while (errorFileUrl is not a non-empty string)
    {
        errorFileUrl = GetImportTargetErrorKeysFileUrl(executionId, entityName)
        if (errorFileUrl is not a non-empty string)
        {
            wait for some time before retrying
        }
    }
}

C#Copy

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

Body
{
    "executionId":"<string>",
    "entityName":"<string>"
}

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value":"<errorkeysfileurl>"
}

Input parameters

ParameterDescription
string executionIdThe execution ID of the import. This is called as Job ID in the UI.
string entityNameThe name of the entity to get the error file for.

Output parameters

ParameterDescription
string errorkeysfileurlThe URL of the error keys file, if the file is available. If the error file is still being generated, or if no errors exist, the method returns an empty string.

GetAzureWritableUrl

The GetAzureWritableUrl API is used to get a writable blob URL. The method includes a shared access signature (SAS) token that is embedded in the URL. You can use this method to upload a data package to the Azure Blob storage container. For on-premises deployments, this API will still return the URL that has been abstracted to local storage.

 Note

An SAS is valid only during an expiry time window. Any request that is issued after the window has passed returns an error. For more information, see Using shared access signatures (SAS).C#Copy

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetAzureWriteUrl
BODY
{
    "uniqueFileName":"<string>"
}

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value": "{\"BlobId\":\"{<GUID>}\",\"BlobUrl\":\"https://<baseurl_id>.blob.core.windows.net/dmf/<uniqueFileName>?<SAS Token>\"}"
    }
}

Input parameters

ParameterDescription
string uniqueFileNameA unique file name that is used to track blob IDs. You can include a globally unique identifier (GUID) to help guarantee a unique file name.

Output parameters

ParameterDescription
string BlobIdThe blob ID of the allocated blob container.
string BlobUrlA URL that has an embedded SAS token. The URL can be used to write to Blob storage.

ImportFromPackage

The ImportFromPackage API is used to initiate an import from the data package that is uploaded to the Blob storage that is associated with your implementation. For on-premises deployments, the import will be initiated from the local storage that the file was uploaded previously to.

 Note

Starting in Platform update 12, the ImportFromPackage API supports composite entities. However, the limitation is that there can be only one composite entity in a package.C#Copy

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ImportFromPackage
BODY
{
    "packageUrl":"<string>",
    "definitionGroupId":"<string>",
    "executionId":"<string>",
    "execute":<bool>,
    "overwrite":<bool>,
    "legalEntityId":"<string>"
}

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value":"<executionId>"
}

Input parameters

ParameterDescription
string packageUrlThe URL of the data package in the Blob storage that is associated with a Finance and Operations app.
string definitionGroupIdThe name of the data project for import.
string executionIdThe ID to use for the job. This is called as Job ID in the UI. If an empty ID is assigned, a new execution ID will be created.
bool executeSet this parameter to True to run the target step. Otherwise, set it to False.
bool overwriteThis parameter must always be set to False when a composite entity is used in a package. Otherwise, set it to True.
string legalEntityIdThe legal entity for the data import.

Output parameters

ParameterDescription
string executionIdThe execution ID of the data import. This is called as Job ID in the UI.

 Note

ImportFromPackage() uses a batch to perform the import. Therefore, parallel processing rules must be used in Data management to perform parallel imports. ImportFromPackage() must not be called in parallel threads. Otherwise, it will fail.

Export APIs

The following APIs are used to export files (data packages).

ExportToPackage

The ExportToPackage API is used to initiate an export of a data package. This API is applicable to both cloud deployments and on-premises deployments.

  • The export data project must be created before you call this API. If the project doesn’t exist, a call to the API returns an error.
  • If change tracking has been turned on, only records that have been created or updated since the last run are exported. (In other words, only the delta is returned.)

C#Copy

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

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value":{
        "value":"<executionId>"
    }
}

Input parameters

ParameterDescription
string definitionGroupIdThe name of the data project for export.
string packageNameThe name of the exported data package.
string executionIdThe ID to use for the job. This is called as Job ID in the UI. If an empty ID is assigned, a new execution ID will be created.
bool reExecuteSet this parameter to True to run the target step. Otherwise, set it to False.
string legalEntityIdThe legal entity for the data import.

Output parameters

ParameterDescription
string executionIdThe execution ID of the data export. This is called as Job ID in the UI.

GetExportedPackageUrl

The GetExportedPackageUrl API is used to get the URL of the data package that was exported by a call to ExportToPackage. This API is applicable to both cloud deployments and on-premises deployments.C#Copy

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExportedPackageUrl
BODY
{"executionId":"<Execution Id>"}

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value":{
        "value":"https://<baseurl_id>.blob.core.windows.net/dmf/<uniqueFileName>?<SAS Token>"
    }
}

Input parameters

ParameterDescription
string executionIdThe execution ID of the data project run. This is called as Job ID in the UI.

Output parameters

ParameterDescription
string BlobUrlA blob URL that has an embedded SAS token. The URL can be used to download the exported data package.

Status check API

The following APIs are used to check status. They are used during both import flows and export flows.

GetExecutionSummaryStatus

The GetExecutionSummaryStatus API is used for both import jobs and export jobs. It’s used to check the status of a data project execution job. This API is applicable to both cloud deployments and on-premises deployments.C#Copy

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus
BODY
{"executionId":"<executionId>"}

Here is an example of a successful response.JSONCopy

HTTP/1.1 200 OK
{
    "@odata.context":"https://<baseurl>/data/$metadata#Edm.String",
    "value":"<executionStatus>"
}

Input parameters

ParameterDescription
string executionIdThe execution ID of the data project run. This is called as Job ID in the UI.

Output parameters

ParameterDescription
DMFExecutionSummaryStatus executionStatusThe execution status. Here are the possible values:UnknownNotRunExecutingSucceededPartiallySucceededFailedCanceled

 Note

The file in Blob storage will remain there for seven days. It will then be automatically deleted.

Getting the list of errors

GetExecutionErrors can be used to get the list of errors in a job execution. The API takes the Execution ID as the parameter, and returns a set of error messages in a JSON list.JSONCopy

POST /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionErrors
BODY
{"executionId":"<executionId>"}

Import and export processes

The following illustration shows how the Data management package methods can be used to import data packages.

Data package file import that uses the Data management package methods

The following illustration shows how the Data management package methods can be used to export data packages.

Data package file export that uses the Data management package methods

A sample console application that showcases the data import and data export methods is available on GitHub. For more information, go to https://github.com/Microsoft/Dynamics-AX-Integration/tree/master/FileBasedIntegrationSamples/ConsoleAppSamples.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s