cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
LuísBasto Frequent Visitor
Frequent Visitor

Error:500 BadRequest when trying to get embed token of new reports

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
};
}
}

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)