redanlaxe/powerbi-embed-php

A PHP library to embed Power BI reports using the App Owns Data (service principal) method.

Installs: 25

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/redanlaxe/powerbi-embed-php

1.0.0 2025-07-30 14:35 UTC

This package is auto-updated.

Last update: 2025-10-30 15:17:05 UTC


README

A PHP library to embed Power BI reports using the "App Owns Data" (service principal) method.

Installation

Install the package via Composer:

composer require redanlaxe/powerbi-embed-php

Usage

  1. Create a configuration array with your Azure AD and Power BI details.

    // config.php
    return [
        'authenticationMode' => 'ServicePrincipal',
        'workspaceId' => 'YOUR_WORKSPACE_ID',
        'reportId' => 'YOUR_REPORT_ID',
        'tenantId' => 'YOUR_TENANT_ID',
        'clientId' => 'YOUR_CLIENT_ID',
        'clientSecret' => 'YOUR_CLIENT_SECRET',
        // ... and other settings
    ];
  2. Instantiate the PbiEmbedService and get the embed parameters.

    <?php
    require 'vendor/autoload.php';
    
    use App\Services\PbiEmbedService;
    
    $config = require 'config.php';
    
    try {
        $pbiService = new PbiEmbedService($config);
        $embedConfig = $pbiService->getEmbedParamsForSingleReport($config['workspaceId'], $config['reportId']);
    
        // The $embedConfig object now contains the accessToken, embedUrl, etc.
        // Send this to your front-end as JSON.
        header('Content-Type: application/json');
        echo json_encode($embedConfig);
    
    } catch (\Exception $e) {
        // Handle exceptions
    }

Running the Example

This repository contains an example implementation in the /examples directory. To run it:

  1. Clone the repository.
  2. Run composer install in the root directory.
  3. Update the configuration in examples/config.php with your credentials.
  4. Use PHP's built-in web server to run the example:
    php -S localhost:8080 -t examples/public
  5. Open http://localhost:8080 in your browser.

License

This project is licensed under the MIT License.