1

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 ? Code with error

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

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
Jishnu G S
  • 11
  • 2
  • You have an authentication error with Azure. See following : https://learn.microsoft.com/en-us/azure/app-service/overview-authentication-authorization – jdweng Apr 15 '23 at 14:26
  • How can i fix the issue? – Jishnu G S Apr 17 '23 at 11:25
  • I do not know which authentication mode the server is requiring. Older servers were using Windows Credentials. New servers are requiring OAUTH 2.0. Azure moved from Windows Credentials to OAUTH 2.0 be compatible with Windows, Linux, and MAC. Setting up server will depend on OS. Not sure if issue is with client, server, or both. – jdweng Apr 17 '23 at 11:47

1 Answers1

0

Note that: To list the Power BI apps, service principal authentication method is not supported.

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 403 error as you are trying to get apps using service principal authentication.

enter image description here

To resolve the issue, you can make use of below commands:

Make sure to connect to PowerBI with service account.

Connect-PowerBIServiceAccount

$apps= Invoke-PowerBIRestMethod -Url 'apps' -Method Get
$apps

enter image description here

Reference:

Apps - Get App - REST API (Power BI Power BI REST APIs)

Rukmini
  • 6,015
  • 2
  • 4
  • 14