Automate Company Creation, User Management and Extensions Installations Through API

Automation APIs are powerful and useful if you need to activate CI/CD pipeline and need to hydrate your tenants.

Automation APIs provide capability for automating company setup through APIs. Once the tenants have been created, the automation APIs can be used, to hydrate the tenant and to bring the tenant to a desired state.

Usually this may involve creating a new company, running RapidStart packages, installing extensions, adding users to user groups and assigning permission sets to users.

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": "mysamza",    
"displayName": "mysamza",    
"evaluationCompany": false,    
"businessProfileId": ""
}

To assign a permission set to a user via an automation API in a Dynamics 365 Business Central tenant, you can send an HTTP GET request to the following endpoint to retrieve the user:

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

Then, you can assign the permission set sending a send a HTTP 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": "Name_Of_Your_Set_Here",  
"companyName" :"CRONUS"
}

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.

Leave a Reply