PHPackages                             juanparati/powerbi - 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. juanparati/powerbi

AbandonedArchivedLibrary[API Development](/categories/api)

juanparati/powerbi
==================

A PowerBI API Interface for PHP

0.8(7y ago)1742MITPHP

Since Feb 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/juanparati/Powerbi)[ Packagist](https://packagist.org/packages/juanparati/powerbi)[ RSS](/packages/juanparati-powerbi/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (2)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\\Juanparati\\PowerBI\\Services\\DatasetGroup\\Juanparati\\PowerBI\\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 \Juanparati\PowerBI\Client($token);

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

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

    // Add columns to table
    $columns = [
        new \Juanparati\PowerBI\Models\ColumnModel(
        [
            'name'     => 'first_column',
            'dataType' => \Juanparati\PowerBI\Enums\DatatypesEnum::STRING
        ]),
        new \Juanparati\PowerBI\Models\ColumnModel(
        [
            'name'     => 'second_column',
            'dataType' => \Juanparati\PowerBI\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 \Juanparati\PowerBI\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 \Juanparati\PowerBI\Client($token);

     $result = (new \Juanparati\PowerBI\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=

```

Supported by
------------

[](#supported-by)

- [Matchbanker.fi](https://matchbanker.fi)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2647d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4caf72b4d969cfb8cdfbdc1d594c85b51c9316caf76b80aa0f9de7e3736cf59f?d=identicon)[juanparati](/maintainers/juanparati)

---

Top Contributors

[![juanparati](https://avatars.githubusercontent.com/u/835173?v=4)](https://github.com/juanparati "juanparati (7 commits)")[![cord](https://avatars.githubusercontent.com/u/158588?v=4)](https://github.com/cord "cord (1 commits)")[![JuanLeadSupply](https://avatars.githubusercontent.com/u/26138256?v=4)](https://github.com/JuanLeadSupply "JuanLeadSupply (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/juanparati-powerbi/health.svg)

```
[![Health](https://phpackages.com/badges/juanparati-powerbi/health.svg)](https://phpackages.com/packages/juanparati-powerbi)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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