Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I created an asp.net api that uses Service Principal to connect to AAD and generate embed tokens, and sends that token to my frontend. It is working well when I use old reports that some of my colleages published last summer, however, we are trying to use Azure Analysis Services and created some new reports to test it.
The api isn't able to generate the embed tokens for these new reports, throwing instead a BadRequest 500. Also while I was figuring out RLS I published another report from a sample given by Microsoft and the same BadRequest happens for the sample report. Are we forgetting some kind of configuration needed to generate tokens? I understand the erros with the reports using AAS but the one I published does not use it afaik.
Here is my code:
private static readonly string Tenant = "tenant";
private static readonly string AppId = "id";
private static readonly string AppSecret = "secret";
private static readonly string Resource = "https://analysis.windows.net/powerbi/api";
private string getToken()
{
var authContext = new AuthenticationContext(Tenant);
var clientCredential = new ClientCredential(AppId, AppSecret);
return authContext.AcquireTokenAsync(Resource, clientCredential).Result.AccessToken;
}
private PowerBIClient getPBIClient()
{
var token = new TokenCredentials(getToken(), "Bearer");
return new PowerBIClient(new Uri("https://api.powerbi.com/"), token);
}
public async Task<ODataResponseListReport> getReports(string ws)
{
PowerBIClient pbiClient = getPBIClient();
var reports = await pbiClient.Reports.GetReportsInGroupAsync(ws);
return reports;
}
public async Task<ReportEmbeddingData> getReportEmbeddingData(string ws, string rep)
{
PowerBIClient pbiClient = getPBIClient();
var report = await pbiClient.Reports.GetReportInGroupAsync(ws, rep);
var embedUrl = report.EmbedUrl;
var reportName = report.Name;
GenerateTokenRequest genTokenReqParam = new GenerateTokenRequest(accessLevel: "view");
string embedToken = (await pbiClient.Reports.GenerateTokenInGroupAsync(ws, rep, genTokenReqParam)).Token;
return new ReportEmbeddingData
{
type = "report",
reportId = rep,
reportName = reportName,
embedUrl = embedUrl,
accessToken = embedToken
};
}
}
Hi @Anonymous
I have a similar issue in my production environment. Everything seems to be working correctly on my localhost, but when I moved to prod I don't receive the embed token.
Did you solve this? How did you do it?
Thank you in advance.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
7 | |
3 | |
2 | |
1 |
User | Count |
---|---|
3 | |
3 | |
3 | |
2 | |
2 |