Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Power Shell Invoke-PowerBIRestMethod -Method Post failing

Hi, 

I'm trying to create script that will refresh some datasets through Power BI API. I have registered App in Active Directory and gave it almost every permissions possible for Power BI Service (only missing ones are "Read and write all content in tenant" and "View all content in tenant"). I am the owner of the refreshed dataset and admin of Data Gateway it accesses.

 

If I put in my script cmdlet:

$urlrefresh = "groups/$groupID/datasets/$datasetID/refreshes"

Invoke-PowerBIRestMethod -Url $urlrefresh  –Method GET

everything is working and script will retrieve list of refreshes, but if I'm trying to do the same with -Method POST, script fails on some kind of write error.

  

I'm assuming it must be some kind of permissions problem, but like I said, App is already having almost all of them.

 

Error message:

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:2 char:1
+ Invoke-PowerBIRestMethod -Url $urlrefresh -Method Post –Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

10 REPLIES 10
mjbirrer
Regular Visitor

@GilbertQ  I know this is an old post, but i'm going throught he same thing...Everything is working fine except the Read All from Tenant.  I am getting an error/alert that "Tenant.Read.All" is not granted for my organization.  Is this something that i just need an O365 admin to approve?  I'm only admin for PowerBI, so not sure what to do at this point.

Hi @mjbirrer 

 

Can you confirm that the app that was created in AAD has got the correct permissions from the person who created it?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

I was the one that created it.  These are the permissions I have added.  Notice the warning on the tenant permission.power bi app.png

 

Here is the script i'm trying to run.  Basically pull all workspaces and associated users.  I can do this for my workspaces, but when i open it up to -Scope Organization, it fails.

Invoke-PowerBIRestMethod : One or more errors occurred.
At C:\Users\jeffrey.birrer\Documents\PowerBI\PowerBI_ExportContent_NEW.ps1:38 char:13
+ $wkpacc = Invoke-PowerBIRestMethod -Url $APIUrl -Method Get|Convert ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
+ FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod


# Authenticate to the Power BI Service API
Connect-PowerBIServiceAccount

# Arrays to hold retrieved data

$access = @()

# Get the workspace data
$workspaces = Get-PowerBIWorkspace #-All -Scope Organization | Where-Object { $_.State -match 'Active' }

 

ForEach($Workspace in $Workspaces)
{ $wkpacc = @()
$Wkpname = $Workspace.Name
$wkpid = $Workspace.Id
$APIUrl = 'groups/'+$wkpid+'/users'
$wkpacc = Invoke-PowerBIRestMethod -Url $APIUrl -Method Get|ConvertFrom-Json|SELECT -ExpandProperty Value|SELECT displayName,groupUserAccessRight|Add-Member -MemberType NoteProperty -Name WorkspaceName -Value $Wkpname -PassThru
$access += $wkpacc
}

$access | Export-CSV "C:\Users\jeffrey.birrer\Desktop\PowerBI_WorkspaceUsers.csv" -NoTypeInformation

GilbertQ
Super User
Super User

Hi there

My understanding is that in order for the API to refresh it actually has to write data back into the dataset.

And that would appear as to why it is failing. I would suggest adding the permissions for read and write and see if the script then works.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

Hi Gilbert,

 

thanks for your reply. App is registered in AD with all permissions possible. Is there something different (perhaps on tetant level) that can override them?

 

Capture.JPG

Hi there

 

I would suggest making sure at the top where it says"Application Permissions you got that set to what is shown below.

 

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

where can I get this screen and configure the permission ? I am service admin.

Hi there

The screenshot above is from Azure Active Directory.

You will have to log into https://portal.azure.com and then active Directory and then App Registrations.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

hi , I tried both app registration and my own credential which is admin. neither works

Anonymous
Not applicable

Power BI embed is the only thing I can see at the moment. what does it mean ? the power bi service is not even registered in Azure ?

 

 

APP REGISTRATION.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors