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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.