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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
varman
Frequent Visitor

Generate token automatically when its getting expired

I'm using embed url for the dashboard. So I'm creating fresh token from postman, and applying the generated token in javascript. This working fine until the token expires. My problem is, I need to always regenerate the token when it expires.

 

I already posted here, but couldn't find a correct answer. power bi embedded access token . And I tried another source to solve Refresh token using JavaScript , but here I face a problem that how to implement the method generateEmbedToken(). 

 

The solution should be really helpful for my project and delay. Thanks in advance

 

 

The following code is working until the token generated form POSTMAN expires. 

window.onload = function () {

var embedUrl=//embedUrl
var id = //id
var accessToken= // accessToken

var embedConfiguration = {
	type: 'report',
	accessToken: accessToken,
	id: id,
	embedUrl: embedUrl,
	settings: {
	    filterPaneEnabled: false,
		navContentPaneEnabled: true
			}
};


var $reportContainer = $('#reportContainer');

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

report.on('loaded', event => {
        report.getFilters()
            .then(filters => {
                filters.push(filter);
                return report.setFilters(filters);
            });});

report.fullscreen();
}

 

3 REPLIES 3
v-micsh-msft
Microsoft Employee
Microsoft Employee

Have you checked the following example?

Refresh token using JavaScript SDK example

The basic step should be:

1. Set a listener for token expire,

2. Use the generateEmbedToken () function to update the embed token.

 

Access token is a little different, see if the following article would help:

Get an authentication access token

 

Regards,

Michael

Thank you so much for your contribution. This code is in .net. But I'm using java and javascript. Can't I implement this in javascript? Is there any tutorial for that? I feel better to do it in javascript. 

Anonymous
Not applicable

What is that first function in the example? Is it triggered by the SDK? Should be executed on load?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors