March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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'"
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
37 | |
22 | |
20 | |
10 | |
9 |
User | Count |
---|---|
60 | |
56 | |
22 | |
14 | |
12 |