Forum Discussion

DerekLedbetter's avatar
DerekLedbetter
Frequent Visitor
1 year ago
Solved

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?

7 Replies

  • $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/..."