crturner
crturner

Reputation: 21

Filtering REST API PowerBI results in Powershell

I am attempting to call the "Get Groups" REST API to return a list of all the workspaces I have access to in Power BI. I want to be able to add a filter to the API call and return only the workspaces whose names have the word "email" in them. I've tried to edit the API url, but nothing seems to change the result set. Any thoughts help!

$GetWorkspaces = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/" -Method Get

I've tried the "try it" function in microsoft docs learn pages, but these urls aren't working either.

Upvotes: 1

Views: 1428

Answers (2)

crturner
crturner

Reputation: 21

This is what worked for me:

$GetWorkspaces = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups?%24filter=contains(name%2C%27email%27)" -Method Get

Upvotes: 1

albvar
albvar

Reputation: 76

Give this a try

  • You can use the $filter query parameter to filter the workspaces by name. The $filter parameter supports OData filter expressions. To filter workspaces whose names contain the word "email", you can use the following expression:

    $filter=indexof(name,'email') ne -1

  • Here is the updated PowerShell script that includes the $filter parameter:

  • The backtick () character is used to escape the $character in the $filter parameter so that PowerShell does not treat it as a variable.

  • This script should return a list of workspaces whose names contain the word "email"

$GetWorkspaces = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/?`$filter=indexof(name,'email') ne -1" -Method Get

Upvotes: 0

Related Questions