Forum Discussion
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?
run a second call
$topn="%24top=5000"
$skip="%24skip=5000"
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$topn&$skip"
7 Replies
- lbendlinSuper User
$uri = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=100" ... $response = Invoke-PowerRestMethod -Url $uri -Method Get -headers $headersWrong uri format. If you use Invoke-PowerBIRestMethod (not Invoke-PowerRestMethod) then you are supposed to supply a relative URI "admin/groups/..."
- DerekLedbetterFrequent Visitor
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 $headersI 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.
- lbendlinSuper User
use $top and $skip