The Business Central Admin Center API makes managing apps and environments easier. It provides a fast way to access the Admin Center functionality without accessing the user interface. In this post, we’ll cover the essentials, from initial app registration in Azure to environment and application management.

  • App Registration
  • Authentication
  • Manage Environments
  • Manage Applications

App Registration


The Admin Center API is only available for cloud environments. The way to access Business Central APIs is always the same, via Azure and using OAuth. The App Registration in Azure is simple, similar to the one we used in this article. Check it out if you need more details.

The only difference is that in this case, we are using “Mobile and desktop applications” for the authentication platform and setting up “http://localhost” as the redirect URI.


After registering the application, authorize the application in the Business Central Admin Center under Microsoft Entra Apps (former Azure Active Directory). If you don’t, you will get a 401 Unauthorized error when trying to connect.


Authentication


To connect to Business Central Admin API we will use PowerShell. Make sure to open it as an Administrator.

We will be following the scripts provided by Microsoft allocated in this GitHub repo:

BCTech/samples/AdminCenterApi at master · microsoft/BCTech · GitHub

As you will see, there are very useful scripts.


We will use the Authenticate.ps1 script first.

BCTech/samples/AdminCenterApi/PowerShell/Authenticate.ps1 at master · microsoft/BCTech · GitHub

You may have to run this command (Set-ExecutionPolicy RemoteSigned) to allow the execution of the script. You can run “Set-ExecutionPolicy Restricted” after to revert to the original state.


Setting the Parameters app Id, RedirectUri, and Tenand Id of Business Central. These will be the variables to use when running the script.

Run this command once. You may have to run the import command as well once installed. MSAL.NET is an authentication library that enables you to acquire tokens from Azure AD to access protected Web APIs.


This is how to retrieve the access token.

If you run the command and encounter an error saying “the command is not completed”, you can add the application secret manually, however, it’s not required if everything goes correctly.

When you run the script the first time, you’ll have to log in with your business central account.


If the execution of the script succeeds, you will get the token and its information.

Now, we are ready to manage the environment and its apps.

Manage Environments


For example, we can create, update, or delete environments. You can find examples here.

BCTech/samples/AdminCenterApi/PowerShell/Environments.ps1 at master · microsoft/BCTech · GitHub

First, we can list all the environments in the tenant.


And, for example, restart an environment if needed.


Manage Applications


With this script, we will see a list of installed AppSource apps for a specific environment.

And see if any of them have available updates.


In short, we can do any operation available from the UI of the Business Central Admin Center. For example, we can see the same information about the “Base Application” update for Sandbox001.


Find the whole script here.

BCTech/samples/AdminCenterApi/PowerShell/Apps.ps1 at master · microsoft/BCTech · GitHub


That´s all. Hope you find it helpful.

How To Access Admin Center API In Business Central

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *