This demonstrates how to use Power BI embedded in US Government cloud and how to embed Q&A. This is an extended sample of Microsoft's App Owns Data.
- Follow the steps described in https://docs.microsoft.com/en-us/power-bi/developer/embedding-content. I have listed more links in credits section to refer.
- Make sure to register your app at https://dev.powerbigov.us/apps. Don't go to https://dev.powerbi.com/apps
- You need to fill missing details in
web.config
before running the application
Settings Key | Settings Value |
---|---|
pbiUsername | Your PowerBI Master User account |
pbiPassword | Your PowerBI Master User account password |
clientId | Guid of Azure AD Native app |
groupId | Guid of Power BI Workspace. see the example below. |
- You need to make sure to have below settings in
Cloud.config
. These are specific toUS Government cloud
.
Settings Key | Settings Value |
---|---|
authorityUrl | https://login.microsoftonline.com/common/oauth2/authorize/ |
resourceUrl | https://analysis.usgovcloudapi.net/powerbi/api |
apiUrl | https://api.powerbigov.us/ |
embedUrlBase | https://app.powerbigov.us |
Microsoft has provided cloud configs for various tenant types in App Owns Data. If anyone other than Power BI Global and Power BI US Goverment looking at this sample, please check for your specific settings here.
Find the demo here (http://cispowerbiembeddedapp.azurewebsites.net/Qna/EmbedQnA/Consumption)
PowerBI Client has Dashboards, Reports, Tiles, Datasets properties and each of these properties expose GenerateTokenInGroupAsync method to generate token. And each Dashboard/Report/Tile has an EembedUrl property, which is required for embedding.
But PowerBI Client does not have Qnas property. Because, if you look at Generate token for Q&A (https://msdn.microsoft.com/library/mt784614.aspx#qanda), we need to generate token using Datasets property. All we are missing is, EmbedUrl for Qna.
To expose Qnas property on PowerBiClient and EmbedUrl property on Qna, I created an extension for PowerBIClient
in PowerBIEmbedded.Extensions project. This gives similar api style as Microsoft.PowerBI.Api
.
Gnerating token...
// Get the qna in the group and dataset.
// original power bi clinet does not have Qnas property. i built an extension in PowerBIEmbedded.Extensions project
var qna = await client.Qnas().GetQnaInGroupAsync(GroupId, DatasetId);
// Generate Embed Token.
var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
var tokenResponse = await client.Datasets.GenerateTokenInGroupAsync(GroupId, DatasetId, generateTokenRequestParameters);
Then, we can use qna.EmbedUrl
// Generate Embed Configuration.
var embedConfig = new QnAEmbedConfig()
{
EmbedToken = tokenResponse,
EmbedUrl = qna.EmbedUrl,
datasetId = DatasetId,
viewMode = "Interactive",
question = ""
};
Madhu Chanthati
Madhu is a Data Scientist who architected & designed data warehouse, built & trained BI models, and created Power BI dashboards, reports, tiles and Qnas on government cloud.
Microsoft
https://github.com/Microsoft/PowerBI-Developer-Samples
Reza Rad
http://radacad.com/integrate-power-bi-into-your-application-part-1-register-your-app
http://radacad.com/integrate-power-bi-into-your-application-part-2-authenticate
http://radacad.com/integrate-power-bi-into-your-application-part-3-embed-content
I will create a project to get embed token for Dashboards, Reports, Tiles, Datasets and Qnas using Azure functions. It will be handy for embedding Power BI in client side apps built using Angular or anyother client side frameworks.