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

3
  • You have an authentication error with Azure. See following : learn.microsoft.com/en-us/azure/app-service/… Commented Apr 15, 2023 at 14:26
  • How can i fix the issue? Commented Apr 17, 2023 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. Commented Apr 17, 2023 at 11:47

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.