powerbipowerbi-api

Get Group ID from Power BI embed URL


I'm trying to embed an existing Power BI Report within our application. From my understanding, the process to do that is as follows...

  1. Given an embed url, something like...
https://app.powerbi.com/reportEmbed?reportId=xxx&autoAuth=true&ctid=xxx
  1. Obtain groupId (workspaceId) of report ❓❓❓

  2. Generate embed token through the Power BI API

POST https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports/${reportId}/GenerateToken

Our API then returns the token back to the client and the token is used by the powerbi-client sdk to show the report. I'm purposefully simplifying how to display the report in the UI as it's not applicable for my issue.

My question is... given the embed url of a report https://app.powerbi.com/reportEmbed?reportId=xxx&autoAuth=true&ctid=xxx, how can I obtain the groupId of that report so I can generate an embed token?

Or perhaps there's a better way to go about obtaining the embed token for an embed URL altogether. I'm open to suggestions.


Solution

  • I figured it out so I'll answer my own question in case anyone else has a similar issue.

    1. Get a list of reports

    myorg/admin/reports returns the reports available to the tenant. The response provides the workspace ID for each report.

    Find the correct report

    const report = response.value.find((r) => r.id === reportId)
    

    The accessing service principal or user will need Tenant.Read.All or Tenant.ReadWrite.All. Additionally, there are some caveats on permissions when accessing this endpoint. Please see the documentation page of this endpoint for additional information.

    The user must have administrator rights (such as Office 365 Global Administrator or Power BI Service Administrator) or authenticate using a service principal. Delegated permissions are supported.

    When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal.

    2. Request Embed Token

    Now that I have the workspace ID for the given report, I can make a request for an embed token that's valid only for that report.

    https://api.powerbi.com/v1.0/myorg/groups/${report.workspaceId}/reports/${reportId}/GenerateToken