Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello all! Is it possible to automatically scrape the list of workspaces from my capacity? I want to export this data into a Power BI report to keep track of new or deleted workspaces on my capacity without having to manually go through the list.
I have looked into the following APIs:
Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Groups - Get Groups - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Unfortunately, they do not have the option to use a Capacity ID in a parameter.
Could this be achieved with web scraping? I have never done this but I would be interested to learn if it would work in my situation!
Thanks!
Solved! Go to Solution.
Hi @bernate ,
Please try
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10"
instead of
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=10"
Besides, I tried @lbendlin 's solution with filter parameter in url and it worked.
Please refer to his solution and use the filter parameter.
Best Regards,
Wearsky
Hi Wearsky, I have already tried this API but I need the option to filter the results by a specific Capacity ID. Across all of our capacities we have many workspaces and this API takes a long time to run/returns many results, so I want to add a Capacity ID parameter.
That's what the Scanner API is for. Set up that process and run it regularly.
Hi Ibendlin- thank you for the suggestion, I will look into this.
or use the $filter on the API call.
Admin - Groups GetGroupsAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn
This is the PowerShell script I am using:
# Replace these values with your own
$tenantId = "xxx"
$appId = "xxx"
$appSecret = "xxx"
# Authenticate with Azure AD using the App Registration
$authUrl = "https://login.microsoftonline.com/xxx/oauth2/v2.0/token"
$body = @{
grant_type = "client_credentials"
client_id = $appId
client_secret = $appSecret
scope = "https://analysis.windows.net/powerbi/api/.default"
}
$authResult = Invoke-WebRequest -Uri $authUrl -Method POST -Body $body
$accessToken = ($authResult.Content | ConvertFrom-Json).access_token
# Call the Power BI REST API to retrieve a list of workspaces
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=10"
$headers = @{
Authorization = "Bearer $accessToken"
}
$Result = Invoke-WebRequest -Uri $Url -Method GET -Headers $headers
$data = $Result.Content
# Output the list of workspaces
$data | Out-File -FilePath C:\Users\xxx\Documents\Script\test2.json -Force
I get this error:
However, when I run the srcipt for the Get Refreshables API, it works. The only thing I change is the API URL to https://api.powerbi.com/v1.0/myorg/admin/capacities/{capacityId}/refreshables?$top={$top}. However, the top= parameter does not work, I get 163 data results even if I set $top=10. Is that syntax incorrect?
Admin - Get Refreshables For Capacity - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Hi @bernate ,
Please try
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10"
instead of
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?$top=10"
Besides, I tried @lbendlin 's solution with filter parameter in url and it worked.
Please refer to his solution and use the filter parameter.
Best Regards,
Wearsky
Hi Wearsky, thank you for your help. The top 10 filter now works! I am still struggling to make the Capacity ID filter work. I cannot try the API in the API documentation because my account is not Admin- I am using Azure AD credentials for the Admin APIs. Here is my code below, I blocked out only the Capacity ID. Is the format correct?
$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10&%24filter=capacityId%20=xxx"
lose the last space (%20).
Like this? "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10&%24filter=capacityId=xxx" It still did not work.
sorry, capacityId eq 'xxx'
Like this?
"https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10&%24filter=capacityIdeqxxx"
or this
"https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10&%24filter=capacityIdeq'xxx'"
Those did not work either.
You are missing the spaces in the ODATA query
It worked! Thank you!
"https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=50&%24filter=capacityId eq 'xxx'"
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
34 | |
30 | |
18 | |
12 | |
8 |
User | Count |
---|---|
50 | |
35 | |
30 | |
15 | |
12 |