Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Nephilim
New Member

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 8
Hari_Adinovus
New Member

@Nephilim Found any solution? for "The sandbox is too restrictive and preventing correct functioning" error

Hi, @Hari_Adinovus.
You may wanna check this Forum: Solved: Re: When clicking on Sign-in on embedded report no... - Microsoft Fabric Community.
It's not exactly the same link used to iframe presented here, but it's a very similar problem that also had the same message "The sandbox is too restrictive and preventing correct functioning"

swat_B
New Member

@Nephilim were you able to find out the reason?

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.

v-yangliu-msft
Community Support
Community Support

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.

Hi Liu Yang,

 

I still haven't gotten it to work, but I have a few aditional question though. Using your scrUrl for the iframe, you mention "your bearer token generated". I put the response from the GenerateToken endpoint below to illustrate. It's the long string in the token-key that I have to put in the config param of the url right?

 

Second question, what is the difference between the url you provided and the one I get back from the reports endpoint (with a much shorter config paran in the url) eg:

 

GenerateToken endpoint response:

{
    "token": "H4sIAAAAAAAEAC2Ux66ZgQmga7we ... pmQxLCJhbGxvd0FbnRlcm5ldCI6dHJ1ZX0=",
    "tokenId": "fb74xxxx-xxxx-xxxx-xxxx-xxxxf4d53b49",
    "expiration": "2024-04-17T09:49:01Z"
}
v-yangliu-msft
Community Support
Community Support

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 g... 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.

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

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors