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
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^7.0
- thenetworg/oauth2-azure: ^2.1
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
-
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 ];
-
Instantiate the
PbiEmbedServiceand 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:
- Clone the repository.
- Run
composer installin the root directory. - Update the configuration in
examples/config.phpwith your credentials. - Use PHP's built-in web server to run the example:
php -S localhost:8080 -t examples/public
- Open
http://localhost:8080in your browser.
License
This project is licensed under the MIT License.