web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Powershell command not working for Publishing the app

(0) ShareShare
ReportReport
Posted on by 21,698 Moderator

Hi All,

I am using a POWERSHELL command to publish the AL app extension in business central, but seems that it not working at all, it asking to enter the User id and Password and then error. Not sure what is the wrong in the command.

$PublisherAppClientId = '413ac35b-e0b6-4610-9a53-72f94d476bf8'
$PublisherAppClientSecretSecret = '9w38QXXXXXXXXXXXXXXLqIRpGAAb95blu'
$appId = '9cd39e6XXXXXXXXXXX956fc360154c'
$scopes = 'api.businesscentral.dynamics.com/.../'
$token = Get-MsalToken `
-ClientId $PublisherAppClientId `
-Scopes $scopes `
-TenantId $appId `
-ClientSecret (ConvertTo-SecureString -String $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken

$token.AccessToken | Get-JWTDetails
$authContext = New-BcAuthContext -refreshToken $token
$apps = 'C:\temp\apps\'
$environment = 'DEV_Sandbox'
Publish-PerTenantExtensionApps -bcAuthContext $authContext -environment $environment -appFiles $apps

pastedimage1669961431901v1.png

I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    hi

    try downloading this

    github.com/.../Download-File.ps1

    in the BcSaas folder you will find

    pastedimage1669971307317v1.png

    DAniele

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    Thanks DAniele, I know this command in Ps1 you just targeting, I am already using that please see my command, but the question is I am not getting the success, please read my question carefully.

    Thanks.

  • Verified answer
    Marco Mels Profile Picture
    on at

    Hello,

    The scope is not correct. For OnPrem this should be:

    $PublisherAppClientId = 'REMOVEFIRSTPART-129c-4435-89f1-bedb3175afd6'

    $PublisherAppClientSecretSecret = 'FpD8REMOVEDVALUECt4eZQSEMaxw '

    $appId = '0b71cREMOVEDASWEL'

    $scopes = 'REMOVEFIRSTPART-129c-4435-89f1-bedb3175afd6/.default'

    $token = Get-MsalToken `

    -ClientId $PublisherAppClientId `

    -Scopes $scopes `

    -TenantId $appId `

    -ClientSecret (ConvertTo-SecureString -String $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken

    $token.AccessToken | Get-JWTDetails

    Did you add a scope to your Azure AD app?

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi Marco Mels ,

    I did follow steps but again I am failing, I am trying to install BC app in Saas version.

    $PublisherAppClientId = '413acXXXXXXXX9a53-72f94d476bf8'
    $PublisherAppClientSecretSecret = '9w38Q~PJoXXXXXX-pmLqIRpGAAb95blu'
    $appId = '9cd39e6bXXXXXX-956fc360154c'
    $scopes = '413ac35XXXXX9a53-72f94d476bf8/.default'
    $token = Get-MsalToken `
    -ClientId $PublisherAppClientId `
    -Scopes $scopes `
    -TenantId $appId `
    -ClientSecret (ConvertTo-SecureString -String $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken

    $token.AccessToken | Get-JWTDetails
    $authContext = New-BcAuthContext -refreshToken $token
    $apps = 'C:\temp\apps\'
    $environment = 'DEV_Sandbox'
    Publish-PerTenantExtensionApps -bcAuthContext $authContext -environment $environment -appFiles $apps

    pastedimage1669988289865v1.png

    I have added the scope like below in Azure app.

    pastedimage1669988351616v2.png

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    The following should work:

    $PublisherAppClientId = 'xxxx-129c-4435-89f1-bedb3175afd6'

    $PublisherAppClientSecretSecret = 'FpD8Q~Sxxxx'

    $appId = 'tenantID'

    $scopes = 'api.businesscentral.dynamics.com/.default'

    $token = Get-MsalToken `

    -ClientId $PublisherAppClientId `

    -Scopes $scopes `

    -TenantId $appId `

    -ClientSecret (ConvertTo-SecureString -String $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken

    $token.AccessToken | Get-JWTDetails

    $authContext = New-BcAuthContext -refreshToken $token -tenantID $appId -includeDeviceLogin

    $apps = 'C:\Users\xxxx\Documents\AL\ALProject3\Default publisher_ALProject3_1.0.0.0.app'

    $environment = 'SandboxBE'

    Publish-PerTenantExtensionApps -bcAuthContext $authContext -environment $environment -appFiles $apps

    Default publisher_ALProject3_1.0.0.0.app

    Publishing and Installing.......completed

    Is that something you can try as a workaround? You can also raise a question on Freddy's Blog.

    Hope this helps.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Thanks Marco Mels ,

    I have again tested

    $PublisherAppClientId = '413aXXX72f94d476bf8'

    $PublisherAppClientSecretSecret = '9w3-pmLqIRpGAAb95blu'

    $appId = '9cd39e6b956fc360154c'

    $scopes = 'api.businesscentral.dynamics.com/.default'

    $token = Get-MsalToken `

       -ClientId $PublisherAppClientId `

       -Scopes $scopes `

       -TenantId $appId `

       -ClientSecret (ConvertTo-SecureString -String $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken

    $token.AccessToken | Get-JWTDetails

    $authContext = New-BcAuthContext -refreshToken $token -tenantID $appId -includeDeviceLogin

    $apps = 'E:\APPInstall\'

    $environment = 'DEV_Sandbox'

    Publish-PerTenantExtensionApps -bcAuthContext $authContext -environment $environment -appFiles $apps

    Now its giving me Scope error.

    pastedimage1670403901128v1.png

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    You are right, forum is automatically removing https from the scope for readability purposes. I will try to add it again (just remove the empty spaces from the url):

    $scopes = 'https : // api.businesscentral.dynamics.com/.default'

    Hope this will work this time.

  • Nitin Verma Profile Picture
    21,698 Moderator on at

    Yes, it took one step ahead, but again saying that token is not valid.

    pastedimage1670414015692v1.png

  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    This should work fine for the authentication part. Also ensure you are using latest BCContainerHelper.

    Uninstall-Module BcContainerHelper -force

    Install-Module BcContainerHelper -force

    $PublisherAppClientId = 'a6b7d1c2-removed'

    $PublisherAppClientSecretSecret = 'FpD8Q~removed'

    $tenantId = '0b71c379-b93c-48bb-removed'

    $scopes = 'https : // api.businesscentral.dynamics.com/.default'

    $bcauthContext = New-BcAuthContext `

       -clientID $PublisherAppClientId `

       -clientSecret (ConvertTo-SecureString -string $PublisherAppClientSecretSecret -AsPlainText -Force) `

       -scopes $scopes `

       -tenantId $tenantId

    Hope this helps you to move forward.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi Marco Mels ,

    Again its failing, but this time its authenticated, but publish command not working.

    $PublisherAppClientId = '41310-9a53-72f94d476bf8'
    $PublisherAppClientSecretSecret = '9kb-pmLqIRpGAAb95blu'
    $appId = '9cd3956fc360154c'
    $scopes = 'api.businesscentral.dynamics.com/.default'
    $bcauthContext = New-BcAuthContext `
    -clientID $PublisherAppClientId `
    -scopes $scopes `
    -tenantId $appId `
    -clientSecret (ConvertTo-SecureString -string $PublisherAppClientSecretSecret -AsPlainText -Force) | Select-Object -Property AccessToken
    $bcauthContext.AccessToken | Get-JWTDetails
    $apps = 'E:\APPInstall\'
    $environment = 'DEV_Sandbox'
    Publish-PerTenantExtensionApps -bcAuthContext $bcauthContext -environment $environment -appFiles $apps

    pastedimage1670545704985v1.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans