I'm trying to get the powerbi apps details using the Azure Cloudshell,
Here is the Powershell script i'm using,
$secret="********"
$tenantId="********"
$appId="********"
$password= ConvertTo-SecureString $secret -AsPlainText -Force
$credential= New-Object System.Management.Automation.PSCredential ($appId, $password)
#Connecting to PowerBI
Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $credential
$accessToken = Get-AzAccessToken
#Get-PowerBIAccessToken
$authHeader = @{
'Content-Type'='application/json'
'Authorization'= $accessToken.Authorization
}
$uri="https://api.powerbi.com/v1.0/myorg/apps/****"
$allapps = (Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET).Value
$allapps.Name
When i'm running this cmd in Azure Cloudshell window, i'm getting bellow error, what could be the problem ?

I have added the SPN to the PowerBI Tenant settings and have API permission as below

The error "Invoke-RestMethod : The remote server returned an error: (
403) Forbidden" usually occurs if there are no proper permissions to perform the action.Here, in your scenario the
403error as you are trying to get apps using service principal authentication.To resolve the issue, you can make use of below commands:
Make sure to connect to PowerBI with service account.
Reference:
Apps - Get App - REST API (Power BI Power BI REST APIs)