Forum Discussion

Nephilim's avatar
Nephilim
New Member
2 years ago

Embeded report in iframe using the API with embedded token

Hi Community,

 

I'm working on embedding a PowerBI report in an iframe, doing the API calls myself.

We are using oauth2: 

https://login.microsoftonline.com/{TenantId}/oauth2/token endpoint.
Then I do an API call to get our reports:
https://api.powerbi.com/v1.0/myorg/groups/{GroupId}/reports, with body: {"accessLevel": "View"}
Than I generate embedded token:
https://api.powerbi.com/v1.0/myorg/groups/{GroupId}/reports/{ReportId}/GenerateToken with body
{"accessLevel": "View",
    "allowSaveAs": "false",
    "identities": [{
       "username": "XXXXX",
       "roles": ["XXXXXXDynamic"],
       "datasets": ["72XXXX-XXXXX-XXXX-XX09"] // (from response of previous call)
}]}
Now I want to use all of this to create the source of the iframe. And I can't find out how to do that successfully.
 
This works but user still needs to login.
<iframe title="Client Portal Report" width="1140" height="541.25" src="https://app.powerbi.com/reportEmbed?reportId={ReportId}&autoAuth=true" frameborder="0" allowFullScreen="true"></iframe>
 
I want to use the generated token to do that for me instead. Wonder if this is possible?

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Nephilim ,

     

    Based on my query and research, it's possible to embed a Power BI report using the generated token instead of relying on user login. Here's how you can achieve that:

    1. Obtain the access token using OAuth2 authentication. You've already outlined this step, where you retrieve the access token from the https://login.microsoftonline.com/{TenantId}/oauth2/token endpoint.
    2. Use the access token to call the Power BI REST API to generate an embed token. You've also covered this step, where you call the GenerateToken endpoint.
    3. Construct the URL for embedding the Power BI report in the iframe. You need to include the report ID and the embed token in the URL

    You may try the URL like this
    <iframe title="Client Portal Report" width="1140" height="541.25" src=https://app.powerbi.com/reportEmbed?reportId={ReportId}&groupId={GroupId}&config=your bearer token generated&$filter=XXXXX frameborder="0" allowFullScreen="true"></iframe>
    Replace {ReportId} and {GroupId} with your report and group IDs, respectively. Also, make sure to replace XXXXX in the $filter parameter with the appropriate filter condition if needed.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Nephilim's avatar
      Nephilim
      New Member

      Hi Liu Yang,

       

      Thank you for the quick response. 

      Unfortunately I dont know if it works, because I get as a response: "The sandbox is too restrictive and preventing correct functioning." It blocked some cookies to "playground.powerbi.com".
      So I asked our PBI and System collegues to look into it first...


      Kind regards
      Marc
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Nephilim ,

     

    Is your problem solved, if so, mark the correct answer as a marker, if not, provide more detailed information and we can help you better!

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • vdmc's avatar
    vdmc
    Frequent Visitor

    Hello Nephilim 
    Have you managed to make it work? I'm considering using this path you presented, but your last message said it wasn't working and I would like to know if it is indeed a viable way to achieve our goal.