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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DerekLedbetter
Frequent Visitor

API - Admin - Groups GetGroupsAsAdmin - can't get it to work

To whom it may concern:

 

I've tried following the documentation at Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn.  Granted I've built a powershell and have been using it for the other "admin API".  When it comes to this one, it will not work.

 

Partial code.

# Authenticate with Azure AD using the App Registration

$uri = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100"
$headers = @{
Authorization = "Bearer $accessToken"
}
# Call the Power BI REST API to retrieve a list of dataflows


$response = Invoke-PowerRestMethod -Url $uri -Method Get -headers $headers

$completeListOfActivityEvents = @()
$completeListOfActivityEvents += $response.value
$continuationToken = $response.continuationToken
$continuationUri = $response.continuationUri
while ($ContinuationToken -ne $null)
{
$response = Invoke-RestMethod -Uri $continuationUri -Method get -Headers $headers
$continuationUri = $response.continuationUri
$continuationToken = $response.continuationToken
$completeListOfActivityEvents += $response.value
}


$completeListOfActivityEvents | Export-Csv -LiteralPath $Path

End code .

For the record, I'm a basic person on API's.  However, I've gotten a lot to work using the SAME code and following the documentation online.  The interesting thing is this one doesn't work.

When it gets to the "while" statement, it jumps to the end and I receive an error - 
[DBG]: PS C:\Users\31096>>
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\Users\31096\OneDrive - Cone Health\Documents\PowerShellScript\PowerBIRESTApiGetGroups.ps1:41 char:33
+ $completeListOfActivityEvents | Export-Csv -LiteralPath $Path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

The question is I'm following the documentation.  I want a list of all workspaces in my organization.  Why doesn't it work?

1 ACCEPTED SOLUTION

run a second call 

 

$topn="%24top=5000"

$skip="%24skip=5000"

$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$topn&$skip"

View solution in original post

7 REPLIES 7
lbendlin
Super User
Super User

$uri = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100"
...
$response = Invoke-PowerRestMethod -Url $uri -Method Get -headers $headers

Wrong uri format. If you use Invoke-PowerBIRestMethod  (not Invoke-PowerRestMethod) then you are supposed to supply a relative URI  "admin/groups/..."

Thanks for the reply.

 

I've not been using - Invoke-PowerBIRestMethod (MicrosoftPowerBIMgmt.Profile) | Microsoft Learn.
I've been using -  Invoke-RestMethod -Uri $Url -Method get -Headers $headers

 

I did get it to work after going back to my original.  The issue, is I have 9424 workspaces and need them all, not just the 5000.

use $top and $skip

 

lbendlin_0-1726748366687.png

 

this works for 5000.  How to get the others is the questions.

 

 CODE.

$authResult = Invoke-WebRequest -Uri $authUrl -Method POST -Body $body
$accessToken = ($authResult.Content | ConvertFrom-Json).access_token

# Call the Power BI REST API to retrieve a list of dataflows
$topn="%24top=5000"
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$topn"
$headers = @{
Authorization = "Bearer $accessToken"
}


$response = Invoke-RestMethod -Uri $Url -Method get -Headers $headers
$completeListOfActivityEvents = @()
$completeListOfActivityEvents += $response.value
$continuationToken = $response.continuationToken
$continuationUri = $response.continuationUri
while ($ContinuationToken -ne $null)
{
$response = Invoke-RestMethod -Uri $continuationUri -Method get -Headers $headers
$continuationUri = $response.continuationUri
$continuationToken = $response.continuationToken
$completeListOfActivityEvents += $response.value
}

END CODE

 

run a second call 

 

$topn="%24top=5000"

$skip="%24skip=5000"

$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$topn&$skip"

Thanks for the assist.

 

I was able to get all the workspaces by performing two calls.

Thanks.

 

I have the documentation.  However, I don't know how to write it in powershell using skip and top.  Please note, I'm a beginner when it comes to API.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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