0

I am retrieving data from Power BI Rest API following the instruction here: https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-get-groups-as-admin#grouptype

A call to retrieve all data works ok. Here is the URL that works:

$url = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top="+$number_of_records+"&%24expand=dataflows,datasets,reports,dashboards,workbooks,users"

But this request return too much data that I want to filter it out.

In particular, I don't want to see personal workspaces. But my calls return an AggregateException error. Here are the URLs I tried that conform with the MSDocs but do not work:

Here I tried to filter out all "PersonalGroup" type

$url1 = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=" + $number_of_records + '&%24filter=type ne' + " 'PersonalGroup'" + '&%24expand=dataflows,dashboards,reports,datasets,users'

And here I tried to keep everything except of "PersonalGroup" type

$url2 = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=" + $number_of_records + '&%24filter=type eq' + " 'Group'" + ' or type eq' + " 'Personal'" + ' or type eq' + " 'Workspace'" + '&%24expand=dataflows,dashboards,reports,datasets,users'

Both throw the same error:

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:15
+     $Result = Invoke-PowerBIRestMethod -Url $url -Method GET
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

Does anyone know how is this fixable as I can't find an answer online and I don't see any errors in my request

Oleg Kazanskyi
  • 196
  • 2
  • 13
  • The exception says WriteError which is probably being caused by writing to a log file after the exception occurs. A ssample of groups is shown here : https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-url-filters?force_isolation=true#standard-url-escape-characters – jdweng Mar 27 '23 at 15:32
  • @jdweng, thank you for the recommendation. I replaced all the special characters. Here is how request look now `https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=5000&%24filter=type%20ne%20%27PersonalGroup%27&%24expand=dataflows,dashboards,reports,datasets,users` – Oleg Kazanskyi Mar 27 '23 at 15:44
  • It still doesn't work for 'ne', but works for 'eq'. – Oleg Kazanskyi Mar 27 '23 at 15:45
  • Maybe NE is just not returning anything and then you are getting an exception someplace else in the code. – jdweng Mar 27 '23 at 15:49
  • The particular line with the `Invoke-PowerBIRestMethod -Url $url -Method GET` gives me an error. I loaded the full data and there are values other than 'PersonalGroup' type. – Oleg Kazanskyi Mar 27 '23 at 16:00
  • You are returning $url1 or $usrl2 but then using $url (no number). If the URL is null, the Invoke will fail. – jdweng Mar 27 '23 at 16:18
  • I numerated "$url"s for simplicity of understanding. Sorry about the confusion. – Oleg Kazanskyi Mar 27 '23 at 16:23
  • Is the $url empty? NE may be empty or the response may have a error and not return 200 OK. – jdweng Mar 27 '23 at 16:57
  • No, the $url is the non-empty string value. Sorry if I am not fully understanding your question. – Oleg Kazanskyi Mar 27 '23 at 19:20
  • I did not say empty string value. It shold be an object – jdweng Mar 27 '23 at 19:51
  • Yes, it's System.Object String – Oleg Kazanskyi Mar 28 '23 at 19:12
  • Is the string a valid URL? The exception is due to string not being a url. The exception is occurring here : $Result = Invoke-PowerBIRestMethod -Url $url -Method GET Are you using the variable $url for two different purposes? – jdweng Mar 28 '23 at 19:32

0 Answers0