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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
mnd
Regular Visitor

Execute queries using Power BI API - authentication issue

Hi All,

 

I am trying to execute a query in a notebook in Fabric using the Power BI rest.

Datasets - Execute Queries In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

 

I have successfully retrieved an access token and I am able call operations such as get dataset but when I try to perform an execute query operation I get an 401 unauthorized error. Both my service principal and the API has acces to the dataset and "Semantic Model Execute Queries REST API" is enanbled in the tenant settings. Are there any other permissions I should be aware of? 

 

Get datasets works perfecty:

header = {'Authorization': f'Bearer {access_token}'}

partitions_url = 'https://api.powerbi.com/v1.0/myorg/groups/' + WorkspaceID + '/datasets/' + DatasetID
response_tables = requests.get(url=partitions_url, headers=header)

 

Execute queries returns unauthorized access:

header = {'Authorization': f'Bearer {access_token}'}
partitions_url = 'https://api.powerbi.com/v1.0/myorg/groups/' + WorkspaceID + '/datasets/' + DatasetID + '/executeQueries'
query_tables =
{
"queries": [
{"query": "EVALUATE INFO.TABLES()"}
]
}
response_tables = requests.post(url=partitions_url, headers=header, json=query_tables)

 

5 REPLIES 5
mnd
Regular Visitor

Hi @mohitkumawat and @ibarrau 

 

Thanks for your inputs. The service principal has build permissions and the model does not have RLS. 

I have tried to create a new plain semantic model in the same workspace with no data sources. I am able to execute queries using the api for this dataset, but as soon as I added a data source (dimension tables from another workspace) I cannot execute queries anymore. Could it be due to missing permissions in the workspace with my data source?

The words "Added a data source (dimension tables from another workspace) sounds like a live connection or composite with direct query. I don't think that's supported. If you can execute queries with one dataset and you can't with another. Then it's permissions or limitation with the semantic model. Usually this works against import models, so data sources shouldn't be a problem. The permissions would be "build for a semantic model".

I hope that make sense.


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Remember that for composite models the user needs to have "registered/installed" each of the participating apps.

ibarrau
Super User
Super User

Hi. As mohitkumawat says, check the permissions at the registered app and make sure the service principal has build permissions.
In addition to his comment, check the limitations. https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries-in-group#limitations

One that can make a problem here is using service principal to execute a query to a semantic model that has RLS. That can't be done for example. Try running simple evaluates to more than one workspace just in case the one you are querying has an issue.

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

mohitkumawat
Super User
Super User

Hi, 

please check your App has added in worskpace as admin and provide deligated permission to the App  of Dataset.ReadWrite.All or Dataset.Read.All.

 

The user must have dataset read and build permissions. For more information, see Manage dataset access permissions.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.