PHPackages                             fmp-dev/power-bi-embedded - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. fmp-dev/power-bi-embedded

ActiveLibrary[API Development](/categories/api)

fmp-dev/power-bi-embedded
=========================

A PowerBI API Interface for PHP

05PHP

Since Aug 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/FMP-Dev/power-bi-embedded)[ Packagist](https://packagist.org/packages/fmp-dev/power-bi-embedded)[ RSS](/packages/fmp-dev-power-bi-embedded/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP PowerBI Interface
=====================

[](#php-powerbi-interface)

1. What is it?
--------------

[](#1-what-is-it)

A PHP Library for the [PowerBI Rest API](https://docs.microsoft.com/en-gb/rest/api/power-bi/).

2. Which services were implemented?
-----------------------------------

[](#2-which-services-were-implemented)

ServiceClassDataset\\PowerBiEmbedded\\Services\\DatasetGroup\\PowerBiEmbedded\\Services\\GroupPlease feel free to contribute with additional services.

3. How it works?
----------------

[](#3-how-it-works)

3.1 Create a dataset into the default workspace/group
-----------------------------------------------------

[](#31-create-a-dataset-into-the-default-workspacegroup)

```
    // Instatiate the client passing the auth token.
    $client = new \PowerBiEmbedded\Client($token);

    // Create a dataset
    $dataset_model              = new \PowerBiEmbedded\Models\DatasetModel();
    $dataset_model->name        = 'My Dataset';
    $dataset_model->defaultMode = \PowerBiEmbedded\Enums\DatasetModeEnum::PUSH;

    // Add table to dataset
    $table = new \PowerBiEmbedded\Models\TableModel();
    $table->name = 'My Table';

    // Add columns to table
    $columns = [
        new \PowerBiEmbedded\Models\ColumnModel(
        [
            'name'     => 'first_column',
            'dataType' => \PowerBiEmbedded\Enums\DatatypesEnum::STRING
        ]),
        new \PowerBiEmbedded\Models\ColumnModel(
        [
            'name'     => 'second_column',
            'dataType' => \PowerBiEmbedded\Enums\DatatypesEnum::INT64
        ]),
    ];

    $table->columns = $columns;

    // Attach tables to dataset model
    $dataset_model->tables = [$table];

    // Create dataset.
    //
    // Note: Use postDatasetInGroup method in case that dataset should be created in a different
    // workspace/group.
    $result = (new \PowerBiEmbedded\Services\Dataset($client))->postDataset($dataset_model);

    // Check if dataset was sucessfully created
    if ($result->isOk()) {
        echo "Dataset created: ";

        // Display dataset Id
        echo $result->response()->id;
    }

```

3.2 Create a workspace/group
----------------------------

[](#32-create-a-workspacegroup)

```
     // Instatiate the client passing the auth token.
     $client = new \PowerBiEmbedded\Client($token);

     $result = (new \PowerBiEmbedded\Services\Group($client))->postGroup('My new workspace');

     if ($result->isOk()) {
         echo "Group created: ";

         // Display dataset Id
         echo $result->response()->id;
     }

```

3.3 Add rows to dataset
-----------------------

[](#33-add-rows-to-dataset)

```
    // Add rows/records
    $rows =
    [
        [
            'first_column'  => 'foo',
            'second_column' => 1
        ],
        [
            'first_column'  => 'bar',
            'second_column' => 2
        ]
    ];

    // Post rows/records.
    //
    // Note: Use postRowsByDatasetIdInGroup method in case that dataset is assigned to the
    // non-default dataset.
    $result = (new Dataset(static::$client))->postRowsByDatasetId($rows, 'My Table', $dataset_id);

    // Obtain the results as an associative array.
    var_dump($result->response(true));

```

4. How to obtain the authentication token (Non-interactive authentication)
--------------------------------------------------------------------------

[](#4-how-to-obtain-the-authentication-token-non-interactive-authentication)

There different ways to obtain the authentication token but this way is most used:

1. Register an [Azure Active Directory App](https://dev.powerbi.com/apps/) with all the required permissions
2. Copy somewhere the "Application Id" and "Client secret"
3. [Grant admin consent to the created application](https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/configure-user-consent#grant-admin-consent-when-registering-an-app-in-the-azure-portal) (Required for non-interactive authentication)
4. Find the tenand ID (Directory ID) and copy it to somewhere (Azure Console -&gt; Dashboard -&gt; Azure Active Directory -&gt; Properties -&gt; Directory ID)
5. Execute the following code (Note: [league/oauth2-client](https://github.com/thephpleague/oauth2-client) library is required):

    ```
     $application_id     = '';
     $application_secret = '';

     $directory_id       = '';

     $user               = '';
     $password           = '';

     $token_file         = 'token.txt';

     // Authenticate
     $provider = new \League\OAuth2\Client\Provider\GenericProvider([
     	'clientId'                => $application_id,
     	'clientSecret'            => $application_secret,
     	'urlAuthorize'            => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
     	'urlAccessToken'          => "https://login.windows.net/$directory_id/oauth2/token",
     	'urlResourceOwnerDetails' => '',
     	'scopes'                  => 'openid',
     ]);

     try {
     	// Try to get an access token using the resource owner password credentials grant.
     	$accessToken = $provider->getAccessToken('password', [
     		'username' => $user,
     		'password' => $password,
     		'resource' => 'https://analysis.windows.net/powerbi/api'
     	]);

     	$token = $accessToken->getToken();

     } catch (\Exception $e) {

     	echo 'Unable to retrieve token' . PHP_EOL;

     	die($e->getMessage());
     }

     // Save token
     file_put_contents($token_file, $token);

     echo '🔑 Token saved in ' . $token_file;

    ```

5. PowerBI API Restrictions
---------------------------

[](#5-powerbi-api-restrictions)

This library doesn't take care about the [PowerBI API Restrictions](https://docs.microsoft.com/en-us/power-bi/developer/api-rest-api-limitations).

6. Unit tests
-------------

[](#6-unit-tests)

Unit tests are not mocked, so it means that request are done against the real PowerBI API. Never execute the unit tests against a production account.

In order to execute the tests the auth token should be added to the environment variable "POWERBI\_AUTH\_TOKEN":

```
    export POWERBI_AUTH_TOKEN=

```

"# power-bi-embedded"

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d76b5adf1663ff03b0831e8be28c723e28e8ad2f198bda8c84fcf4f1b50d8e5?d=identicon)[FMP-Dev](/maintainers/FMP-Dev)

---

Top Contributors

[![FMP-Dev](https://avatars.githubusercontent.com/u/109966286?v=4)](https://github.com/FMP-Dev "FMP-Dev (5 commits)")

### Embed Badge

![Health badge](/badges/fmp-dev-power-bi-embedded/health.svg)

```
[![Health](https://phpackages.com/badges/fmp-dev-power-bi-embedded/health.svg)](https://phpackages.com/packages/fmp-dev-power-bi-embedded)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
