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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
VikiK
New Member

Generate Bearer Token for React embedded report

Hello - Looking for some direction and detailed instructions, please.
I am trying to generate a token for embedded reports in a React front end.

I have followed this article: https://medium.com/globant/how-to-embed-a-power-bi-report-in-react-f27e975e0a

I found this code: https://github.com/KotanaSai21/powerbi-embedded-React-demo/blob/main/GenerateToken.csx

I wrote a Java API for React to call in case it needed to be client->server->client thing.

 

Step 1 (in the article) will work; I get an access_token.

However, using that access_token as a bearer token in Steps 2 and Steps3 result in a 401.

(Using Postman)

Also, when using Embed Token - Generate Token - REST API (Power BI Power BI REST APIs) | Microsoft Learn,

(as also described in Step 3 of the article), it is successful from here when I "try this", but again a 401 from Postman. I notice that the Bearer Token used here in the MS Learn link is much longer than the access_token I receive in Step 1 from Postman.  Where/How does it get the Bearer Token used in the MS Learn link?

Looking for some direction on doing this programmatically, please - either via React or Java microservice - I just need it to work. 😃
I am using a service principal for tenant id, along with client_id,  and client_secret, ect.
Thanks in advance-

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @VikiK ,

 

 

The bearer token used in the MS Learn link is likely an embed token generated specifically for the report.
To generate an embed token programmatically, use the `GenerateToken` API. This API provides additional functions, such as creating tokens for multiple items.

 

Troubleshooting 401 Errors:
- Double-check that the access token you're using is valid and has the necessary permissions.
- Ensure that the report ID and embed URL match the report you want to embed.
- Verify that the report is shared with the service principal (app registration) in Power BI.

 

For more details, please refer: reactjs - How to Embed Power BI Report in React app ? 

How to embed a Power BI item in a React app | Microsoft Learn

Embed Token - Reports GenerateTokenInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Lear...

Generate an embed token in Power BI embedded analytics - Power BI | Microsoft Learn

 

Best Regards,

Neeko Tang

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @VikiK ,

 

 

The bearer token used in the MS Learn link is likely an embed token generated specifically for the report.
To generate an embed token programmatically, use the `GenerateToken` API. This API provides additional functions, such as creating tokens for multiple items.

 

Troubleshooting 401 Errors:
- Double-check that the access token you're using is valid and has the necessary permissions.
- Ensure that the report ID and embed URL match the report you want to embed.
- Verify that the report is shared with the service principal (app registration) in Power BI.

 

For more details, please refer: reactjs - How to Embed Power BI Report in React app ? 

How to embed a Power BI item in a React app | Microsoft Learn

Embed Token - Reports GenerateTokenInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Lear...

Generate an embed token in Power BI embedded analytics - Power BI | Microsoft Learn

 

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors