Forum Discussion
API Document is very confusing, unable to generate token
Thank you for directing me to the blog Ted.
I'm trying to use third party embedding using power BI pro license. So, my understanding is i'm going to need an access token using which i'll have to generate embedd token before i can show my report in simple html and page page.
I was able to get access token using with all read/write access. (tested it in postman for working)
please do let me know if my understanding is right and if yes, what should be the next steps
TIA
Irfan Harun
Yes, your understanding is correct. Once you obtain an access token, next you call into the Power BI Service API to get embedding data for a report and an embed token. If you use the Power BI API SDK, then you have a librtary to help with this. Here is a simple example of getting the embedding data and an embed token for a report.
public static ReportEmbeddingData GetReportEmbeddingData() {
PowerBIClient pbiClient = GetPowerBiClient();
var report = pbiClient.Reports.GetReportInGroup(workspaceId, reportId);
var embedUrl = report.EmbedUrl;
var reportName = report.Name;
// create token request object
GenerateTokenRequest generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
// call to Power BI Service API and pass GenerateTokenRequest object to generate embed token
string embedToken = pbiClient.Reports.GenerateTokenInGroup(workspaceId,
report.Id,
generateTokenRequestParameters).Token;
return new ReportEmbeddingData {
reportId = reportId,
reportName = reportName,
embedUrl = embedUrl,
accessToken = embedToken
};
}- irfanharun7 years agoFrequent Visitor
Thank you again Ted.
I'm trying to do this only through jquery and my intention was to get the access token through an Ajax call and then use the access token to get the embed token.
However, I'm getting CORS error when trying to get the access token. This works fine for some reason in Postman but not in my html page.
var settings = { "async": true, "crossDomain": true, "url": "https://login.microsoftonline.com/common/oauth2/token", "method": "POST", "headers": { "content-type": "application/x-www-form-urlencoded", "cache-control": "no-cache", "postman-token": "f89336c3-4da3-37db-7c6e-6ceeec420920", }, dataType: 'jsonp', "data": { "grant_type": "password", "username": "[email protected]", "password": "asd!23", "client_id": "741312d6-f40e-45b4-b491-fff4ea3655c3", "resource": "https://analysis.windows.net/powerbi/api" } } $.ajax(settings).done(function (response) { console.log(response); });Can you please provide an input on this.
Thanks
Irfan