Automation APIs in Dynamics 365 Business Central

Dynamics 365 Business Central also exposes APIs for automating tenant-related tasks, such as the following:

  • Creating companies
  • Managing users, groups, and permissions
  • Handling extensions (the installation/uninstallation of per-tenant extensions)
  • Importing and applying configuration packages

Automation APIs are under the /microsoft/automation namespace. For example, to create a company in a Dynamics 365 Business Central tenant, you can send an HTTP POST request to the following endpoint:

POST https://api.businesscentral.dynamics.com/v2.0/api/microsoft/automation/{apiVersion}/companies({companyId})/automationCompanies
Authorization: Bearer {token}
Content-type: application/json
{
"name": "PACKT PUB",
"displayName": "PACKT Publishing",
"evaluationCompany": false,
"businessProfileId": ""
}

To retrieve users on your tenant, you need to send a GET request to the following endpoint:

GET https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/beta/companies({id})/users

When you have retrieved your user's details, to assign a permission set to a user via an automation API, you need to send a POST request to the following endpoint:

POST https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/{apiVersion}/companies({companyId})//users({userSecurityId})/userGroupMembers
Authorization: Bearer {token}

{
"code": "D365 EXT. ACCOUNTANT",
"companyName" :"CRONUS IT"
}

To modify the details of a Dynamics 365 Business Central user, you need to send an HTTP PATCH request to the following endpoint:

PATCH https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/beta/companies({id})/users({userSecurityId})
Content-type: application/json
If-Match:*
{
"state": "Enabled",
"expiryDate": "2021-01-01T21:00:53.444Z"
}

To get a list of the extensions installed on a tenant, you can send a GET request to the following endpoint:

GET https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/{apiVersion}/companies({{companyid}})/extensions

To handle the installation and uninstallation of extensions, you can send a POST request to the following bound actions:

  • Microsoft.NAV.install
  • Microsoft.NAV.uninstall

For example, to uninstall a previously installed extension, you can send a POST request to the following endpoint:

POST https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/{apiVersion}/companies({companyId})//extensions({extensionId})/Microsoft.NAV.uninstall
Authorization: Bearer {token}

AppSource extensions must be previously installed on the tenant; then, you can install/uninstall them via the automation API.

If you have a per-tenant extension, you can upload and install it on the SaaS tenant by sending a PATCH request to the following endpoint:

PATCH https://api.businesscentral.dynamics.com/v1.0/api/microsoft/automation/beta/companies({companyId})/extensionUpload(0)/content
Authorization : Bearer {token}
Content-type : application/octet-stream
If-Match:-*

Here, the request body content must have the .app package file (binary) to upload on the tenant. With automation APIs, authentication must be OAuth 2.0 Authorization (Bearer Token).

More information about Dynamics 365 Business Central APIs can be found at https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/itpro-introduction-to-automation-apis.

Automation APIs are extremely important and powerful if you need to activate a CI/CD pipeline and if you need to hydrate tenants.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.106.69