Dynamics 365 Business Central: receive notifications when AppSource apps updates are available in a tenant

When you install AppSource apps in a Dynamics 365 Business Central tenant, app updates are automatically handled by Microsoft during a major or a minor update of the tenant (this is handled by the value of the App Update Cadence parameter in the tenant’s Admin Center):

But during the lifetime of a minor update (tipically a month) you could have the need to discover if an AppSource app that you have installed in your tenant has available updates in the marketplace or not. This is particularly important in order to immediately detect hotfixes or new versions published by the app’s publisher (that can be you or can be someone else).

The traditional way to discover if AppSource apps updates are available for a given tenant is to go in Dynamics 365 Business Central Admin Center, select your environment and then select Apps:

Here you have the list of the AppSource apps installed in your tenant and you can see if updates are available for a given app or not and you can immediately update the app (and its dependencies) from here:

But how can I be notified if an AppSource app is available on my customer’s tenant without going to the Admin Center? When managing tons of Dynamics 365 Business Central SaaS customers, I would like to receive an automatic notification when AppSource apps are available on my customer’s tenant. In the notification I would like to have the list of available updates with the related details for each app to update.

The solution: using Admin Center APIs from a Powershell script

The Business Central Admin Center APIs enable administrators to programmatically do administrative tasks for a Business Central tenant. You can see more infpormations on how to enable the Admin Center APIs for a given tenant and configure authorizations at the follwoing link:

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api

Dynamics 365 Business Central Admin Center exposes the /availableUpdates API, that gets informations about new app versions that are available for apps currently installed on the environment.

Why not using a Powershell script (scheduled for example to to run for a given tenant every day) that:

  • Call the /availableUpdates API for a given tenant
  • Retrieves the list of available app updates
  • If an app update is available, sends a notification to a pre-defined mail address with the details of the available updates.

This is something that some partners have asked for, so I’ve decided to share a Powershell script that I’m using from quite a long time.

The script is reported here and also it’s available on my GitHub script repo:

$clientid     = "YOUR_CLIENT_ID"
$clientsecret = "YOUR_CLIENT_SECRET"
$scope = "https://api.businesscentral.dynamics.com/.default"
$tenant = "YOUR_TENANT_ID"
$environment = "YOUR_ENVIRONMENT_NAME"
# Get access token
$token = Get-MsalToken `
-ClientId $clientid `
-TenantId $tenant `
-Scopes $scope `
-ClientSecret (ConvertTo-SecureString -String $clientsecret -AsPlainText -Force)
$accessToken = ConvertTo-SecureString -String $token.AccessToken -AsPlainText -Force

# Get available updates
$response= Invoke-WebRequest `
-Method Get `
-Uri "https://api.businesscentral.dynamics.com/admin/v2.1/applications/businesscentral/environments/$environment/apps/availableUpdates" `
-Authentication OAuth `
-Token $accessToken

if ((ConvertFrom-Json $response.Content).value.length -gt 0) {
$jsonresponse = ConvertFrom-Json $response.Content
$mailBody = "<b><u>APP UPDATES AVAILABLE:</u></b> <br>"
foreach($app in $jsonresponse.value)
{
$mailBody += "<b>App ID:</b> " + $app.id + " <b>Name:</b> " + $app.name + " <b>Publisher:</b> " + $app.publisher + " <b>Version:</b> " + $app.version + "<br>"
}
}
else {
Write-Output "NO APP UPDATES FOUND."
$mailBody = "";
}

if ($mailBody.Length -gt 0)
{
#Sending a notification email
$UserName = "YOUR_SMTP_USERNAME"
$Password = "YOUR_SMTP_PASSWORD"
$from = "YOUR_SENDING_EMAIL_ADDRESS";
$to = "YOUR_RECEIVING_EMAIL_ADDRESS";
$SecurePassword = ConvertTo-SecureString -string $password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
$EmailParams = @{
From = $from
To = $to
Subject = "APP UPDATES AVAILABLE FOR TENANT " + $tenant
Body = $mailBody
SmtpServer = "smtp.office365.com"
Port = 587
UseSsl = $true
Credential = $Cred
BodyAsHtml = $true
}
Send-MailMessage @EmailParams
}

The output of this script is an HTML email like the following:

You can extend the script as needed and also you can use a different type of notifications (feel free to send me a pull request if you add something cool). Enjoy…

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.