microsoft / AL-Go

The plug-and-play DevOps solution for Business Central app development on GitHub
MIT License
270 stars 113 forks source link

"No company" error when trying to deploy to environment #614

Open cegekaJG opened 1 year ago

cegekaJG commented 1 year ago

I've correctly set up an AAD app to publish via AL Go, but during the Deploy step, I've encountered the following error:

Run microsoft/AL-Go-Actions/Deploy@v3.1
Run try { D:\a\_actions\microsoft\AL-Go-Actions\v3.1\Deploy/Deploy.ps1 -actor $ENV:_actor -token $ENV:_token -parentTelemetryScopeJson $ENV:_parentTelemetryScopeJson -projects $ENV:_projects -environmentName $ENV:_environmentName -artifacts $ENV:_artifacts -type $ENV:_type } catch { Write-Host "::Error::Unexpected error when running action ($($_.Exception.Message.Replace("`r",'').Replace("`n",' ')))"; exit 1 }

Downloading BcContainerHelper latest version from CDN
BcContainerHelper version 5.0.4
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Analyzing releases https://api.github.com/repos/CBS-BC-AT/CLT.Base/releases
Downloading release 18.07.2023c, projects *, type Apps
project '*'
https://api.github.com/repos/CBS-BC-AT/CLT.Base/releases/assets/117525818
D:\a\CLT.Base\CLT.Base\.artifacts\CLT.Base-main-Apps-1.3.29.0.zip
Downloading release 18.07.2023c, projects *, type Dependencies
project '*'
Apps to deploy
D:\a\CLT.Base\CLT.Base\.artifacts\CLT.Base-main-Apps-1.3.29.0.zip
Attempting authentication to https://api.businesscentral.dynamics.com/.default using clientCredentials...
Authenticated as app ***
https://businesscentral.dynamics.com/3d975565-f8df-4015-b7ed-ad61ef72aab3/SANDBOX/deployment/url
Using S2S, publishing apps using automation API
https://api.businesscentral.dynamics.com/v2.0/SANDBOX/api/microsoft/automation/v2.0/companies
Publish-PerTenantExtensionApps Telemetry Correlation Id: d43db734-5757-4074-8f3a-84f0f150df8d
Error: Deploying to SANDBOX failed.  No company 
Removing BcContainerHelper
Error: Process completed with exit code 1.
freddydk commented 1 year ago

I can see you are using S2S - did you register the AAD App inside BC?

cegekaJG commented 1 year ago

Yes, using the Azure Active Directory Apps page in the webclient. Am I supposed to register in the BC Admin Center?

freddydk commented 1 year ago

No, only the AAD App registration page. I use this every day - not sure what you have done wrongly.

cegekaJG commented 1 year ago

What is throwing the error? Has anyone reported the same error message in the past?

freddydk commented 1 year ago

It looks like calling this API: https://api.businesscentral.dynamics.com/v2.0/SANDBOX/api/microsoft/automation/v2.0/companies

doesn't return any company, which I assume is because you somehow do not have access to enumerate companies with the S2S token.

cegekaJG commented 1 year ago

Maybe the permissions are insufficient? Is this correct? image I tried sending an API request to list the available environments using Thunder Client and the app for the authorization, but this is what I got:

{
  "type": "https://tools.ietf.org/html/rfc7235#section-3.1",
  "title": "Unauthorized",
  "status": 401,
  "extensions": {
    "traceId": "00-6af452d572eea673de098821408079ca-bda4797d9440d09f-01"
  }
}