cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
verma_pragya
Regular Visitor

Power BI embedding for PHP web application

Is it possible to embed a Power BI report in a php application. If so, how to generate access token and embed url using php?

 

Any help will be appreciated. Thank you in advance.

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @verma_pragya ,

 

There are a number of steps you need to take:

  1. Create a Workspace Collection inside Azure and get the Access keys (I understand you've completed this)
  2. Create a Workspace using the REST API - with PHP, you'll be using probably use CURL for this. Don't forget to add the Authorization header with one of the Access keys and use POST as described here. Note that you don't need to actually post anything, just use the POST method, otherwise you'll just get a JSON with the existing workspaces. POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces Authorization: AppKey {yourAccessKey}

Now you should have a workspace id.

  1. Import a .pbix file from Power BI Desktop into your workspace. This is also achieved using the REST API. don't forget to add the datasetDisplayName parameter to the URL, ie: POST the data and file to https://api.powerbi.com/v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports?datasetDi...}

Now you should have a report id.

  1. Create an embed token. This is a JSON Web Token (JWT). You can use php-jwt for this. The JWT claims payload required for PBIe are listed here. Note that you only need to pass the payload and your Access key to php-jwt.
  2. With that token, you can finally embed the report in your application using PowerBI Javascript. You can just copy the powerbi.js file from the dist dir if you wish. You need to create a configuration object as described here. var embedConfiguration = { type: 'report', accessToken: {your-jwt-token-string}, id: {your-report-id-string}, embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed' }; var $reportContainer = $('#reportContainer'); //some div var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

And now you should have a report in your app.

 

Reference: https://stackoverflow.com/questions/39770804/use-powerbi-embedded-in-php

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @verma_pragya ,

 

There are a number of steps you need to take:

  1. Create a Workspace Collection inside Azure and get the Access keys (I understand you've completed this)
  2. Create a Workspace using the REST API - with PHP, you'll be using probably use CURL for this. Don't forget to add the Authorization header with one of the Access keys and use POST as described here. Note that you don't need to actually post anything, just use the POST method, otherwise you'll just get a JSON with the existing workspaces. POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces Authorization: AppKey {yourAccessKey}

Now you should have a workspace id.

  1. Import a .pbix file from Power BI Desktop into your workspace. This is also achieved using the REST API. don't forget to add the datasetDisplayName parameter to the URL, ie: POST the data and file to https://api.powerbi.com/v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports?datasetDi...}

Now you should have a report id.

  1. Create an embed token. This is a JSON Web Token (JWT). You can use php-jwt for this. The JWT claims payload required for PBIe are listed here. Note that you only need to pass the payload and your Access key to php-jwt.
  2. With that token, you can finally embed the report in your application using PowerBI Javascript. You can just copy the powerbi.js file from the dist dir if you wish. You need to create a configuration object as described here. var embedConfiguration = { type: 'report', accessToken: {your-jwt-token-string}, id: {your-report-id-string}, embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed' }; var $reportContainer = $('#reportContainer'); //some div var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

And now you should have a report in your app.

 

Reference: https://stackoverflow.com/questions/39770804/use-powerbi-embedded-in-php

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

lbendlin
Super User III
Super User III

Power BI Embedded (microsoft.com)  You'll probably want to go with the JavaScript API.  Do you have Azure AD?

Yes, I have Azure AD. I can embed a report using c# and python to generate the access token and embed URL, and javascript rest APIs to embed. However, I have no clue on how to generate access token using PHP, since I want to embed report in my PHP application.

I'm working on a similar problem...trying to embed for customers in Drupal. So far, my solution is to use the python (with flask) solution and potentially embed the flask service URL (localhost:5000 for now) in an iframe to serve the report. It works in my local Drupal instance. I'm working on how to pass the Drupal user id to the Javascript and then to the PowerBI API for row level security. 
Good luck!!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.