Power BI Embedded example using cURL and PHP

Recently Microsoft re-launched PowerBI Embedded as part of the PowerBI Premium offering. Instead of a pay-per-view pricing model Microsoft now offers dedicated capacity. There are three parts to get this new PowerBI Embedded working:

  1. Configuration in Azure (Register an app, activate the PowerBI Embedded capacity)
  2. Configuration in the PowerBI service (create a PowerBI app and activate the premium capacity)
  3. Development of a web application (requesting a token, requesting the embedded url and embed the actual report using javascript)

All above is explained in detail in the getting started guide. However, the last part is explained using a .NET example app. In this post we’ll show an alternative method using PHP and cURL.

Our basic PHP example uses two cURL requests: the first request will request a token, the second request uses this token to retrieve the embedded URL of the report. We’ll store the token and the embedded URL in PHP variables and use these in the JavaScript code to finally embed the report in an HTML div attribute.


  1. Request the token
  2. Decode the result and store the token in a variable
  3. Request the embedded URL using the token variable
  4. Store the embedded URL in a variable
  5. Embed the report with Javascript using the two variables above


Step 1) Request the token:

/* Get oauth2 token using a POST request */

$curlPostToken = curl_init();

curl_setopt_array($curlPostToken, array(

CURLOPT_URL => "https://login.windows.net/common/oauth2/token",








grant_type => 'password',

scope => 'openid',

resource => 'https://analysis.windows.net/powerbi/api',

client_id => '', // Registered App ApplicationID

username => '', // for example john.doe@yourdomain.com

password => '' // Azure password for above user



$tokenResponse = curl_exec($curlPostToken);

$tokenError = curl_error($curlPostToken);



Step 2) Decode the result and store the token in a variable:

// decode result, and store the access_token in $embeddedToken variable:

$tokenResult = json_decode($tokenResponse, true);

$token = $tokenResult["access_token"];

$embeddedToken = "Bearer "  . ' ' .  $token;


Step 3) Use this token variable in a GET request to get the embedded url:

/*      Use the token to get an embedded URL using a GET request */

$curlGetUrl = curl_init();


curl_setopt_array($curlGetUrl, array(

CURLOPT_URL => "https://api.powerbi.com/v1.0/myorg/groups/YourGroupID/reports/",








"Authorization: $embeddedToken",

"Cache-Control: no-cache",



$embedResponse = curl_exec($curlGetUrl);

$embedError = curl_error($curlGetUrl);



Step 4) Decode the result, retrieve the embedded URL and store this URL in a second variable:

if ($embedError) {

echo "cURL Error #:" . $embedError;

} else {

$embedResponse = json_decode($embedResponse, true);

$embedUrl = $embedResponse['value'][0]['embedUrl'];



5. In the last part we use the JavaScript code provided by Microsoft to embed the report:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

<script src="scripts/powerbi.js"></script>

<div id="reportContainer"></div>



// 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 embedConfiguration= {

type: 'report',

id: 'YourReportId', // the report ID

embedUrl: "<?php echo $embedUrl ?>",

accessToken: "<?php echo $token; ?>" ,


var $reportContainer = $('#reportContainer');

var report = powerbi.embed($reportContainer.get(0), embedConfiguration);


Lars Bouwens is Business Intelligence consultant at Motion10 and likes to read and write about Power BI and Azure.

Leave a Reply to John Helmuth Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


  1. Thanks for the tutorial, it helped a lot.
    I have a question, when displaying the report appears the field: ... Export data, does it know in any way to remove this?

    thank you

  2. Stan Evers

    Nice blog Lars! Great to see you found an alternative to embed Power BI with PHP and cURL.

  3. a debt of gratitude is in order for sharing data exceptionally pleasant blog thank you lars!

  4. Howard

    Thanks Lars. Would you have any idea where to start if I constantly get wrong username/password when requesting the token in step 1? I've confirmed my details are good, tried it every possible way, but still get the error. If there is any place to even start troubleshooting this, it would be great! If not, no problem, thanks for helping by posting the code!

  5. udhayavanan

    thanks for the tutorial which made easy,
    but i forget the missing option publish to web. without publish to web how i can get embed url. is there any option?

    always i am getting this content is not available message.

  6. M

    Hey! Thanks Man! Finally found a work around

  7. Dallas

    Hi Lars,

    Thank you for sharing your expertise and knowledge and in a practical manner - Cheers!
    I would like my customers to login to my app - and display an embedded report filtered on their data?
    in pseudo - Would it happen by calling the onfilterchange at the onload time and then use a param from their profile?
    Thanks again!

    • Lars Bouwens

      You should use the customer username as a variable in your token. You can then also use this username as username() in your Power BI report. You could filter the data set dynamically based on the username.

      • Hi can you provide code.how would i sent username to powerbi when i generate token,because two username field will be there.One is for login another is for RLS.How can i do for this

  8. how can i impemennt rls through this code anyone can help me

    • Lars Bouwens

      I wrote this post in 2018, MS has changed a lot regarding Power BI Embedded since then. The token we request in step 1 works for this specific scenario. If you want to implement RLS you need to request a token for a specific user and use that token in the next steps.

      A good starting point would be to try to generate a token using the following documentation:

  9. Robert Davies

    I have a question. I'm trying to implement this under the App Owns Data model for Power BI and it feels from the result that is 90%. I don't suypport you have any suggestions for App Owns Data?

    • Lars Bouwens

      I am not sure if I understand your question. This scenario is the 'app owns data' model, because end users do not have to bring their own Power BI license.

  10. Mathu

    Hi Lars,
    I have power Bi embedded ULR, if we use IFRAME the report comming but the problem was the URL was displaying in HTML iframe , is there any solution to use the embedded URL without IFRAME. Can we use PHP or javascript to embedded the report.


    • Lars Bouwens

      Can you share your code? I am not sure what you mean by the URL is showing in the iframe.

  11. Hander Valencias

    Hello, excellent article,
    As of today, June 18, 2020, there is no easier way to perform a CULR consultation:

    Example of invocation with CURL

    curl --user "nameuser": "Password" --request GET 'https://test-website/api/v1/casos/abiertos?equipo=true'

    Excuse my English


  12. Lars,

    Thanks for the demonstration of accessing PowerBI embedded reports via the App Owns Data flow.

    Do you know if it is possible to use Certificates in the Azure Key Store using a service principal (
    https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal-certificate) with code similar to your demonstration code?

    This is mostly to help me understand the underlying request/response flow, ideally there would be a PHP library that matches up with Microsoft's C# libraries so that their documentation is more helpful to those of us who are not using C#.

Next ArticleImplementing ‘Always Encrypted’ in an ETL process