Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.

 

lbendlin
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.