Anna
Anna

Reputation: 1

Power BI REST API request error 403 when querying the dataset

I want to query the Power BI dataset using Power BI REST API, app to app authentication (Service Principal). I am getting Error 403 (access forbidden) when sending request to Power BI dataset.

I have:

  1. Azure AD App registered
  2. SP with **Dataset.Read.All **delegated permission
  3. SP added to AAD security group
  4. the security group is allowed to use Power BI API (setting under Tenant enabled)
  5. the security group has Admin role in Power BI Service workspace. I am able to generate the access Token successfully. but then I am getting Error 403 (access forbidden) when sending request to Power BI dataset using GET or POST method, for example:

GET https://api.powerbi.com/v1.0/myorg/groups/{{group_id}}/datasets Authorization: Bearer Token

Can anyone help on that, what is missing here, thank you.

Upvotes: 0

Views: 3520

Answers (1)

Sridevi
Sridevi

Reputation: 22552

In my case, I got 403 Forbidden error when I tried to query the data set with token generated with invalid scope:

GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets

Response:

enter image description here

To resolve the error, make sure to generate access token by passing scope value as https://analysis.windows.net/powerbi/api/.default

I created one AAD security group and added PowerBI App service principal to it like this:

enter image description here

Now, I allowed this group to call Power BI API by adding it under below option in Admin portal:

enter image description here

Make sure to grant access to either the service principal or security group for your Power Bi workspace:

enter image description here

Note that, you need to wait for 15-20 minutes after granting access to the service principal as there will be delay.

Now, I generated access token using client credentials flow via Postman with below parameters:

POST https://login.microsoftonline.com/tenantId/oauth2/v2.0/token
grant_type:client_credentials
client_id: appId 
client_secret: secret 
scope: https://analysis.windows.net/powerbi/api/.default

Response:

enter image description here

When I used this token to query dataset, I got response successfully like this:

GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets

Response:

enter image description here

Reference: Embed Power BI content with service principal and an application secret - Power BI | Microsoft

Upvotes: 1

Related Questions