powerbipowerbi-embedded

Getting Bearer Access Token for PowerBI


I am working on an Angular app in which we have to show PowerBI reports. The user will select organization from a dropdown and the page should show PowerBI report for the selected organization. We have all the required information for each of the oraganization (ClientId, TenantId, Client Secret).

I have done most of the settings, however stuck at getting the right token (the token I am getting gives 401 error).

Here is my Postman setup to get token: (URL: https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token) enter image description here

As you can see I am getting token. However, for the report specific API (To get EmbedURL) I am getting 401: (URL: https://api.powerbi.com/v1.0/myorg/groups/{groupid}/reports/{reportId})

enter image description here

Further, if I copy and paste token from https://learn.microsoft.com/en-us/rest/api/power-bi/reports/get-reports-in-group#code-try-0 then it works and I am getting all the info I need. Here is what I mean:

enter image description here

Am I missing something? I am fairly sure that this is something to do with scope. Which scope being used in the example page by Microsoft? Any idea/way to figure this out?

I also gave correct API permissions in the Azure portal:

enter image description here


Solution

  • The Error you're facing while getting the Embed URL PowerBINotAuthorizedException is due to either Unauthorized group or wrong group Id. Refer Troubleshoot documentation for Error.

    Refer to this documentation Embed using service principal. Follow the steps, where you need to add service principal to your workspace. Then You would be able to hit the API and get the Embed URL.