Reputation: 1
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:
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
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:
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:
Now, I allowed this group to call Power BI API by adding it under below option in Admin portal:
Make sure to grant access to either the service principal or security group for your Power Bi workspace:
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:
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:
Reference: Embed Power BI content with service principal and an application secret - Power BI | Microsoft
Upvotes: 1