Invoke-PowerBIRestMethod: One or more errors occurred. (Response > status code does not indicate success: 401 (Unauthorized)

80 views Asked by At

I try to get Power Bi transactions in PowerShell but got 401 unauthorized error.

I run first the commando 'Login-PowerBIServiceAccount' and the browser opened automatically to sign in with my serviceaccount. I sign in and run the script below:

Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/groups/SOME-GUID/dataflows/SOME-GUID/transactions' -Method GET

Then I got this error:

Invoke-PowerBIRestMethod: One or more errors occurred. (Response status code does not indicate success: 401 (Unauthorized).)

Which permissions do I need to give my self to run this script?

1

There are 1 answers

0
KEM On BEST ANSWER

You need to use Connect-PowerBIServiceAccount for authentication.

$tenantId = "xxx"

$appId = "xxx"

$clientSecret = "xxx"

$securePassword = ConvertTo-SecureString $clientSecret -Force -AsPlainText

$credential = New-Object Management.Automation.PSCredential($appId, $securePassword)

Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -Credential $credential

Invoke-PowerBIRestMethod -Url $getWorkspacesUrl -Method Get