Forum Discussion
Embed Dashboard into .net core web application App Owns Data
Hello,
I'm currently working on an .net core web application that should enable users to view PowerBI reports/dashboards without needing to sign in to Power BI.
I found the App Owns data option and I got it working for reports, but when I try to do it with dashboards I get an forbidden error, with exception: ”Embedding is disabled on tenant level”.
I have used the template which I found here https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-core and added another method to handle Dashboard based on different suggestions I found here.
Any help is appreciated and if you need anymore information please ask.
These are the steps I have done:
I'm using the workspaceId and dashboardId from the link
https://app.powerbi.com/groups/workspaceId/dashboards/dashboardId
I have added the application as an admin to the workspace
And the Service principal has the following permissions:
This is the message that gets sent to power bi
This is the error I get back
C# to get embeded parameters
public EmbedParams GetDasboardEmbedParams(Guid workspaceId, Guid dashboardId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
// Get report info
var pbiDashboard = pbiClient.Dashboards.GetDashboardInGroup(workspaceId, dashboardId);
// Add report data for embedding
var embedDashboards = new List<EmbedReport>() {
new EmbedReport
{
ReportId = pbiDashboard.Id, ReportName = pbiDashboard.DisplayName, EmbedUrl = pbiDashboard.EmbedUrl
}
};
// Get Embed token multiple resources
var embedToken = GetDashboardEmbedToken(workspaceId, pbiDashboard.Id);
// Capture embed params
var embedParams = new EmbedParams
{
EmbedReport = embedDashboards,
Type = "Dashboard",
EmbedToken = embedToken
};
return embedParams;
}
/// <summary>
/// Get Embed token for single report, multiple datasets, and an optional target workspace
/// </summary>
/// <returns>Embed token</returns>
public EmbedToken GetDashboardEmbedToken(Guid groupId, Guid dashboardId)
{
PowerBIClient pbiClient = this.GetPowerBIClient();
try
{
return pbiClient.Dashboards.GenerateTokenInGroup(groupId, dashboardId, new GenerateTokenRequest(accessLevel: "view"));
}catch(HttpOperationException ex)
{
throw ex;
}
}
Javascript getting dashboard
$(function () {
var models = window["powerbi-client"].models;
var reportContainer = $("#report-container").get(0);
// Initialize iframe for embedding report
powerbi.bootstrap(reportContainer, { type: "report" });
$.ajax({
type: "GET",
url: "/embedinfo/getdashboardembedinfo",
success: function (data) {
embedData = $.parseJSON(data);
reportLoadConfig = {
type: "dashboard",
tokenType: models.TokenType.Embed,
accessToken: embedData.EmbedToken.Token,
pageView: "fitToWidth",
embedUrl: embedData.EmbedReport[0].EmbedUrl,
settings: {
background: models.BackgroundType.Transparent
},
id: "322b56eb-6007-4859-b654-581ddf968aab"
};
// Use the token expiry to regenerate Embed token for seamless end user experience
// Refer https://aka.ms/RefreshEmbedToken
tokenExpiry = embedData.EmbedToken.Expiration;
// Embed Power BI report when Access token and Embed URL are available
var report = powerbi.embed(reportContainer, reportLoadConfig);
// Clear any other loaded handler events
report.off("loaded");
// Triggers when a report schema is successfully loaded
report.on("loaded", function () {
console.log("Report load successful");
});
// Clear any other rendered handler events
report.off("rendered");
// Triggers when a report is successfully embedded in UI
report.on("rendered", function () {
console.log("Report render successful");
});
// Clear any other error handler events
report.off("error");
// Handle embed errors
report.on("error", function (event) {
var errorMsg = event.detail;
// Use errorMsg variable to log error in any destination of choice
console.error(errorMsg);
return;
});
},
error: function (err) {
// Show error container
var errorContainer = $(".error-container");
$(".embed-container").hide();
errorContainer.show();
// Format error message
var errMessageHtml = "<strong> Error Details: </strong> <br/>" + err.responseText;
errMessageHtml = errMessageHtml.split("\n").join("<br/>");
// Show error message on UI
errorContainer.append(errMessageHtml);
}
});
});
5 Replies
- AnonymousNot applicable
Hi Svante_noltorp,
According to your error message, it seems related to the embed feature settings. I'd like to suggest you ask your admin to check these settings first.
BTW, since you are work with 'service principal', did you enable the 'service principal' usage on power bi APIs? It may affect API usages.
Regards,
Xiaoxin Sheng- Svante_noltorpFrequent Visitor
Hi Anonymous,
We have looked at the link you posted and what we can see it's correct.
Is there a different between a Report and Dashboard in the developer settings? My admin told me that both Report and Dashboard is under the same option and since it's working with Reports it should therefore work with Dashboards.
As for enable 'service principal' on power bi APIs, we have enable the Dashboard.Read.All in the same manner as Report.Read.All. We have added all Read.All options on the principal.
Best Regards,
Svante Noltorp
- AnonymousNot applicable
HI Svante_noltorp,
For option settings, they should apply to both reports and dashboards. (I haven't found the standalone options)
BTW, for the embedded dashboard, you also need to check the source contents permission(dashboard can be designed by different report contents) and feature usage limitations(e.g. q&A tile).
Regards,Xiaoxin Sheng