Dynamics 365 Business Central API Integration

I needed a way to integrate with Dynamics 365 Business Central and a .Net application running in Azure. (see Deploying .NET Applications To Azure), these are the high level steps.

Entra

Access

Your user will need the following access

  1. Access to the tenant
  2. Needs the roles Application Administrator and Cloud Application Administrator

App Registration

  1. Register the application in Entra, you will need the application (client) ID, its a GUID, example 00000000-0000-0000-0000-000000000001
  1. Optionally set App Roles if required, see Entra RBAC For Applications
  2. Create the app secret and set its expiry date, the secret is a string, example SSs00~SSSSSSSSSSSssssssssss.SSSSSsss~Sss
  1. Set the API permission
1
2
AdminCenter.ReadWrite.All
API.ReadWrite.All

Testing with postman

  1. Construct the request
1
2
3
4
5
6
POST: https://login.microsoftonline.com/{{tenant-id}}/oauth2/v2.0/token
Auth Basic: `{{client-id}}` `{{client-secret}}`

BODY: x-www-form-urlencoded
grant_type: client_credentials
scope: https://api.businesscentral.dynamics.com/.default

Optional test to set the JWT

1
2
3
4
5
6
7
function main(){
var jsonData = JSON.parse(responseBody);
var jwt = jsonData.access_token;
postman.setEnvironmentVariable("access_token", jwt);
}

main();
  1. Validate token

Example roles as seen when running the token through https://jwt.io/

1
2
3
4
5
6
"roles": [
"Automation.ReadWrite.All",
"app_access",
"AdminCenter.ReadWrite.All",
"API.ReadWrite.All"
],

Dynamics

  1. Set up the Microsoft Entra application in Business Central

Example permission

1
ADMINISTRATOR

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/automation-apis-using-s2s-authentication#task-2-set-up-the-microsoft-entra-application-in-

Dyanamis API

Using the token as a bearer you can then make requests, these are all GET and {{env}} can be production|sandbox

Base to discovery the API and get all companies

1
2
3
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/subscriptions
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/companies

Then to find some data using a company-id from the above, it will be a guid, example 00000000-0000-0000-0000-000000000002. You can also filter by sales-quote-id which is also a guid, example 00000000-0000-0000-0000-000000000003

1
2
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/companies({{company-id}})/salesQuotes
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/companies({{company-id}})/salesQuotes({{sales-quote-id}})

It also supports filters

1
2
3
4
5
# Number greater than 430
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/companies({{company-id}})/salesQuotes?$filter=number gt 'SQ000430'

# DocumentDate greater than 2025-05-02 where the format is YYYY-MM-DD
https://api.businesscentral.dynamics.com/v2.0/{{env}}/api/v2.0/companies({{company-id}})/salesQuotes?$filter=documentDate gt 2025-05-02