I had a nightmare time trying to figure out a simple example for JavaScript API, for PowerBI embed solution using PHP programming language.
I hope developers post every single step solutions when possible as it's very nightmarish to figure out that which we don't know.
I hope following notes could be useful to some, and if I myself have forgotten to include any steps or the steps are no longer valid due to upgrades or software changes, please post it in comments and I will try to update the steps if possible or create a new blog and add a link to it in this blog post.
PHP Code:
User JavaScript API to implement html
URL: https://github.com/Microsoft/PowerBI-JavaScript
HTML Code:
Note:
In some instances you may need a "Native" app and a "Web App / API" app under "Enterprise Apps" or "App Registrations" in "Azure Portal"
I hope developers post every single step solutions when possible as it's very nightmarish to figure out that which we don't know.
I hope following notes could be useful to some, and if I myself have forgotten to include any steps or the steps are no longer valid due to upgrades or software changes, please post it in comments and I will try to update the steps if possible or create a new blog and add a link to it in this blog post.
Power BI
Azure Portal
URL: https://portal.azure.com
Setting up an Embed App
Embed Onboarding
URL: https://app.powerbi.com/embedsetup/appownsdata
- Sign In
- “your-org-email-org-office-365-email”
- Register your application
- Application Name: Power BI Integration
- API access
- Read only APIs (check items below)
- Read all datasets
- Read all dashboards
- Read all reports
- Read all groups
- Read all workspaces
- Read all capacities
- Register (click button)
- Record:
- Application ID: {GUID}
- Create a workspace
- Name your workspace: DWC Public Workspace
- Create app workspace (click button)
- Record:
- Workspace ID: {GUID}
- Import content
- Upload .pbix file (check)
- Browse (click link)
- File: Select from computer
- Import (click button)
- Record:
- Report ID: : {GUID}
- Grant permissions
- Popup
- Select the checkbox for delegating permissions as organization.
Endpoints
Home > WIT - App registrations > Endpoints
FEDERATION METADATA DOCUMENT
https://login.microsoftonline.com/{GUID}/federationmetadata/2007-06/federationmetadata.xml
WS-FEDERATION SIGN-ON ENDPOINT
https://login.microsoftonline.com/{GUID}/wsfed
SAML-P SIGN-ON ENDPOINT
https://login.microsoftonline.com/{GUID}/saml2
SAML-P SIGN-OUT ENDPOINT
https://login.microsoftonline.com/{GUID}/saml2
MICROSOFT AZURE AD GRAPH API ENDPOINT
https://graph.windows.net/{GUID}
OAUTH 2.0 TOKEN ENDPOINT
https://login.microsoftonline.com/{GUID}/oauth2/token
OAUTH 2.0 AUTHORIZATION ENDPOINT
https://login.microsoftonline.com/{GUID}/oauth2/authorize
PHP Code:
// start $post_values = array( 'grant_type' => 'password', 'client_id' => '{application_id}', 'scope' => '*', 'resource' => 'https://analysis.windows.net/powerbi/api', 'username' => 'web-app-email-address', 'password' => 'web-app-password', ); $post_url = 'https://login.microsoftonline.com/{GUID}/oauth2/token'; $response = Http::post_to_url($post_values, $post_url); /* * result items = token_type scope expires_in ext_expires_in not_before resource access_token refresh_token */ $embed_info = array(); if (!empty($response[0])) { $result = json_decode($response[0]); debug::variable($result); $embed_info['token_type'] = $result->token_type; $embed_info['scope'] = $result->scope; $embed_info['expires_in'] = $result->expires_in; $embed_info['ext_expires_in'] = $result->ext_expires_in; $embed_info['not_before'] = $result->not_before; $embed_info['resource'] = $result->resource; $embed_info['access_token'] = $result->access_token; $embed_info['refresh_token'] = $result->refresh_token; $embed_info['embed_url'] = 'https://app.powerbi.com/reportEmbed?' . 'reportId=' . {GUID} . '&groupId=' . {GUID} ; $embed_info['report_id'] = {GUID}; } // end
User JavaScript API to implement html
URL: https://github.com/Microsoft/PowerBI-JavaScript
HTML Code:
// start
div id="reportContainer" /div
!-- libraries --
script src="/javascript/powerbi/other/es6-promise.auto.min.js"/script
script src="/javascript/powerbi/other/fetch.js"/script
script src="/javascript/powerbi/powerbi.min.js"/script
script
// Read embed application token from Model
var accessToken = $embed_app_info['access_token'];
// Read embed URL from Model
var embedUrl = $embed_app_info['embed_url'];
// Read report Id from Model
var embedReportId = $embed_app_info['report_id'];
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
permissions: models.Permissions.All,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};
// Get a reference to the embedded report HTML element
var reportContainer = $('#reportContainer')[0];
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
/script
// end
Note:
In some instances you may need a "Native" app and a "Web App / API" app under "Enterprise Apps" or "App Registrations" in "Azure Portal"
Comments
Post a Comment