Forum Discussion
PowerShell WriteError: InvokePowerBIRestMethod when authenticated with Connect-PowerBIServiceAccount
Thank you for helping. I thought that just 'apps' was the url and the method was 'get', but I understand I am a novice. How can I find this?
By way of example, if you want to get a list of workspace you can use Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn
The URL you would use is https://api.powerbi.com/v1.0/myorg/admin/groups?$top={$top} as outlined in the docs.
When invoking the method, you can leave off the https://api.powerbi.com/v1.0/myorg, it is assumed. Top $top parameter is required, so try it with any number between 1 and 5000 (the limit).
For eaxample, the following will return the top 10 workspaces:
Invoke-PowerBIRestMethod -Method GET -Url "admin/groups?`$top=10"
The docs are actually very usefull and the TryIt feature lets you play with the optional parameters to see thier impact. I highly recommend using the TryIt functionality to see how it works.
If you are new to PowerShell I highly recommed Learn Windows PowerShell in a Month of Lunches, Second Edition (manning.com)
Hope this helps.
- willz06jw3 years agoHelper II
Thank you. So my (limited) understanding from the docs is that calling the url 'apps' calls https://api.powerbi.com/v1.0/myorg/apps/. Calling the url 'admin/apps' calls https://api.powerbi.com/v1.0/myorg/admin/apps
If my understanding is right, then that might be an issue per your above comment. But when I change the command to:Invoke-PowerBIRestMethod -Url 'admin/apps' -Method Get
I still get the error- m-colbert3 years agoResolver III
Please reference the docs for each method for what is required. For getting apps, Admin - Apps GetAppsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn you'll see that $top is required.
Try
Invoke-PowerBIRestMethod -Method GET -Url "admin/apps?`$top=10"
Hope this helps.
- willz06jw3 years agoHelper II
When I run my script with PowerBI-Login, it works, when I run my script with Connect-PowerBIServiceAccount -ServicePrincipal it does not work. I believe something I am doing in the authentication is wrong.
I tried the $top changes, but it still did not run. For the $top part, the documentation says, "The requested number of entries in the refresh history. If not provided, the default is all available entries." The documentation has an error. It should say required: false. I only know this since it runs without $top when I authenticate with "PowerBI-Login"