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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
RaulSantos
Regular Visitor

Use API to execute query to dataset giving Unauthorized Error

Hello,

 

I am having troubles trying to execute the following endpoint:

https://api.powerbi.com/v1.0/myorg/datasets/{dataset_id}/executeQueries

Body:

{
  "queries": [
    {
      "query": "EVALUATE 'my_table'"
    }
  ]
}
 
In the same workspace, I have a lot of different datasets.
I tried to use the endpoint on dataset_1 and it worked without any problems
But once I tried the same thing with dataset_2 I got the following error:
 
401 Unauthorized
{
    "error": {
        "code": "PowerBINotAuthorizedException",
        "pbi.error": {
            "code": "PowerBINotAuthorizedException",
            "parameters": {},
            "details": [],
            "exceptionCulprit": 1
        }
    }
}
 
I checked the permissions and settings and everything seems to be configured the same way.
I also realized that If I delete the dataset and put it back the dataset, I'm able to run the endpoint on this new dataset.
I also tried to download it and overwrite it but this doesn't work
 
I'm trying to run the endpoints with the help of a bearer token from created with the Service Principal.
On both datasets I have the same SQL analytics Endpoint and a Lakehouse 
 
1 ACCEPTED SOLUTION
v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

Thank you for reaching out to Microsoft Fabric Community.

The 401 Unauthorized error likely means the Service Principal lacks access to the specific dataset, even if it works for others in the same workspace. Make sure the SPN has Build or Read permissions directly on the dataset (via Dataset > Settings > Permissions). Also, confirm that Service Principal access is enabled in the Power BI Admin Portal and the SPN is in the allowed security group. Older datasets may have hidden ownership issues - deleting and republishing resets ownership, which is why that workaround helped. Reassigning access or publishing from the SPN should resolve it.

Thank you.

View solution in original post

6 REPLIES 6
v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

I hope the information provided is helpful.I wanted to check whether you find some time to test the solution provided..?Please let us know if you need any further assistance.

Thank you.

 

v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.

Thank you.

v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

Thank you for the update.

v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

I wanted to check if you had the opportunity to review the information provided and resolve the issue..?Please let us know if you need any further assistance.We are happy to help.

Thank you.

Hello @v-venuppu 

Thank you for your help in advance

Unfortunately I still didn't have the chance to test it since I was off this 3 days.

 

I'll try to solve it this week.

As soon as I have some feedback I'll put the feedback here 

 

Thank you once again 🙂 

v-venuppu
Community Support
Community Support

Hi @RaulSantos ,

Thank you for reaching out to Microsoft Fabric Community.

The 401 Unauthorized error likely means the Service Principal lacks access to the specific dataset, even if it works for others in the same workspace. Make sure the SPN has Build or Read permissions directly on the dataset (via Dataset > Settings > Permissions). Also, confirm that Service Principal access is enabled in the Power BI Admin Portal and the SPN is in the allowed security group. Older datasets may have hidden ownership issues - deleting and republishing resets ownership, which is why that workaround helped. Reassigning access or publishing from the SPN should resolve it.

Thank you.

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.