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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.