Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
bernate
Helper II
Helper II

Get list of workspaces on capacity

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. 

bernate_0-1728076597438.png

 

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!

 

1 ACCEPTED 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.

vxiaocliumsft_0-1728970815339.png

 

Best Regards,

Wearsky

View solution in original post

14 REPLIES 14
v-xiaocliu-msft
Community Support
Community Support

Hi @bernate ,

 

GetGroups api will return the capacity id.

vxiaocliumsft_0-1728270037924.png

 

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.

lbendlin
Super User
Super User

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.

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:

bernate_0-1728514146819.png

 

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?

bernate_1-1728514500695.png

 

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.

vxiaocliumsft_0-1728970815339.png

 

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? 

bernate_0-1729022001207.png

$Url = "https://api.powerbi.com/v1.0/myorg/admin/groups?%24top=10&%24filter=capacityId%20=xxx"

lose the last space (%20).

sorry, capacityId eq 'xxx'

You are missing the spaces in the ODATA query

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors