Dynamics 365 Business Central - OAuth 2.0 APIs with Insomnia

Postman has been a staple of API testing, but there are alternatives. Here is a very short basic guide on setting up Insomnia to use OAuth 2.0 for Business Central API testing.

First check out the article from Yun Zhu and setup an app registration in Entra. Using OAuth to connect Business Central APIs and Web Service in Postman | Dynamics 365 Lab (yzhums.com)

Visit The Collaborative API Development Platform - Insomnia, create a free account / login and download the desktop app.


You can create a new project with Local Vault for credentials or a Cloud Sync project if you want to collaborate and/or are trusting!


To test the BC APIs create a New Collection in the project you just created and enter the URL of the API you want to test out.


Here is an example API endpoint to get the list of companies from your environment.

https://api.businesscentral.dynamics.com/v2.0/<your tenant ID>/<Environment>/api/v2.0/companies

Here is an example of a complete HTTP request URL for my sandbox:

https://api.businesscentral.dynamics.com/v2.0/9a3b927f-095b-42b5-bf6e-58b99e2f3bbf/Sandbox/api/v2.0/companies

The tenant ID (1) and environment name (2) you can check in your BC web client URL 



This HTTP request URL goes into box as shown, then also grab the Auth URL, Access URL, Client ID and Client Secret (see the steps from Yun Zhu's blog post for that) and update the Auth tab.


The only extra step you need to do in Azure that Yun Zhu doesn't mention is to add BC redirect URL: 

https://businesscentral.dynamics.com/OAuthLanding.htm



Visit the App registration Overview (1) and access the Endpoints (2) fly out to view the Authorisation URL (3) and the Token Access URL (4) that are needed for the HTTP request OAuth token. 


Finally you are ready to get the OAuth token, scroll down on the Auth tab and click Fetch


You should now be prompted to login and once completed the Access Token will show a value 


Now you can Send the HTTP request (1) and get some results (2) a response of 200 means all went as expected.


That's it!