Reputation: 89
I'm working on integrating Power BI Embedded using the REST API to retrieve the list of dashboards. I'm using client credentials flow with the correct client ID and client secret to obtain an access token.
My app is registered in Azure AD, and I’ve granted Dashboard.Read.All permissions (delegated type). However, despite having a valid token, I'm still receiving a 401 Unauthorized error when trying to access the API endpoint (../v1.0/myorg/dashboards). I’ve ensured the token is included as a Bearer token in the request headers. Has anyone encountered a similar issue or know what could be causing this?
Upvotes: 0
Views: 390
Reputation: 972
Note: Client Credentials flow is not supported for accessing myorg
as it is comes under service principal authentication. To get dashboard present in myorg
you need generate the token using authorization_code flow.
Initially, I registered Microsoft Entra ID application, added and granted API permission like below:
To get code
, I ran below authorization request in browser:
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?
client_id=<client_id>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://analysis.windows.net/powerbi/api/.default
&state=12345
Now, I generated the access token using authorization_code flow with below parameter:
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token
client_id=<app_id>
client_secret = <client_secret>
redirect_uri= https://jwt.ms
code=<code which generated from browser>
scope= https://analysis.windows.net/powerbi/api/.default
grant_type = authorization_code
Response:
When I use this generated access token to list dashboards from my workspace, I got response like below.
To list dashboards from workspace:
GET https://api.powerbi.com/v1.0/myorg/dashboards
As I don't have any dashboards in my workspace, null value with Status 200 OK
.
If still issue persist, Ensure to add Entra ID registered app to Power BI workspace with Admin or Contributor access.
Reference:
Get Dashboards - Power BI REST APIs
MsDoc-Embed Power BI content with service principal and client secret
Upvotes: 0