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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Michele_Zanoni
Frequent Visitor

Obtaining token to embed report

Hello all,

 

I write for some clarifications. Following the instructions in the last two videos of the documentation section of this page, I have embedded a report into an html code that I have run and that places a report into a web page. So far so good.

 

Problem is, I have obtained the token by running the code from the app owns data on this github in debug mode. I realize now (it probably was obvious to more savvy developer, but not to me) that that was likely just a trick. In fact, I have noticed that the token after a while expires and I need to run the software again and obtain a new (different) token.

 

Am I correct in thinking that the authorization token is not static, i.e. it changes and I will not be able to simply copy paste it into my html code once and be done with it?

 

Assuming I have to obtain the token dynamically, could you give me a suggestion on where to start? I know little (read nothing) of GET, POST, PUT and so on. I'm trying to reverse engineering what I find scattered on forums and the like. For example I have been using this simple code to embed the report:

 

// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;

var embedConfiguration = {
	type: 'report',
	id: '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
	embedUrl: 'https://app.powerbi.com/reportEmbed',
	tokenType: models.TokenType.Aad,
	accessToken: 'e4...rf'
};

var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

 

What can I use to get the accessToken? Should I expand this html code adding something before it? Should I use the code in the example "App owns data"? But in that case, where shall I put the code I have downloaded from Github? 

2 REPLIES 2
v-micsh-msft
Microsoft Employee
Microsoft Employee

Take a look at the following:

Refresh token using JavaScript SDK example

 

Basically you need to set a listener on token expiration, once expired, call the SetAccessToken function to update it.

 

Regards,

Michael

Michael,

 

thank you for your answer. Unfortunately we need to take a step back. As the document at the link says, I'd need to implement a function generateEmbedToken() that calls the application Back End. Problem is, I've never written a single line of code in javascript, C# or html, nor do I know how Front End or Back End work or communicate.

 

I've downloaded the code app owns data at this link, I can try to understand what it does and I would be content with simply changing what I need in order to glue together something that works and embeds a report in a web page that I can later on go and change to my liking, but that's a second step. But the first obstacle is already "how do I turn the code I have downloaded in to a web page?"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.