Download the PHP package juanparati/powerbi without Composer

On this page you can find all versions of the php package juanparati/powerbi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package powerbi

PHP PowerBI Interface

1. What is it?

A PHP Library for the PowerBI Rest API.

2. Which services were implemented?

Service Class
Dataset \Juanparati\PowerBI\Services\Dataset
Group \Juanparati\PowerBI\Services\Group

Please feel free to contribute with additional services.

3. How it works?

3.1 Create a dataset into the default workspace/group

    // 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

     // 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

    // 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)

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

  1. Register an Azure Active Directory App with all the required permissions
  2. Copy somewhere the "Application Id" and "Client secret"
  3. Grant admin consent to the created application (Required for non-interactive authentication)
  4. Find the tenand ID (Directory ID) and copy it to somewhere (Azure Console -> Dashboard -> Azure Active Directory -> Properties -> Directory ID)
  5. Execute the following code (Note: league/oauth2-client library is required):

    $application_id     = '<The application id>';
    $application_secret = '<The application secret>';
    
    $directory_id       = '<The azure tenant id>';
    
    $user               = '<Admin e-mail or username used in the app registration process>';
    $password           = '<Admin password used in the app registration process>';
    
    $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

This library doesn't take care about the PowerBI API Restrictions.

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=<Your token>

Supported by


All versions of powerbi with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package juanparati/powerbi contains the following files

Loading the files please wait ....