Forum Discussion
PowerShell WriteError: InvokePowerBIRestMethod when authenticated with Connect-PowerBIServiceAccount
Which API method are you trying to invoke? If you are trying to inboke a method that is not an admin method, than the service principal must have access to the workspace.
Just the general "Invoke-PowerBIRestMethod -Url 'apps' -Method Get" fails
- m-colbert3 years ago
Resolver III
To be more clear, what URL are you using. That defines which method you are calling.
- willz06jw3 years ago
Helper II
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?
- m-colbert3 years ago
Resolver III
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.