PHPackages                             cx-engine/expert-stats-api-sdk-php - 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. cx-engine/expert-stats-api-sdk-php

ActiveLibrary[API Development](/categories/api)

cx-engine/expert-stats-api-sdk-php
==================================

The Official Expert statistics API PHP Client/SDK

v1.2.0(3mo ago)0752↓78.6%MITPHPPHP &gt;=8.2

Since Apr 1Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/CX-engine/expert-stats-api-sdk-php)[ Packagist](https://packagist.org/packages/cx-engine/expert-stats-api-sdk-php)[ RSS](/packages/cx-engine-expert-stats-api-sdk-php/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (14)Versions (16)Used By (0)

Expert statistics PHP Client
============================

[](#expert-statistics-php-client)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Version on Packagist](https://camo.githubusercontent.com/9b5cbb3f638c671bb3dd2163f292be10efd2e6fcfb8935f6a88494c566e6cdbf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f43582d656e67696e652f6578706572742d73746174732d6170692d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/CX-engine/expert-stats-api-sdk-php)[![Total Downloads](https://camo.githubusercontent.com/bbf0055eee0d53bb50745b67f5ab2ffe9c51afc7e4e5105531db615e8586b909/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f43582d656e67696e652f6578706572742d73746174732d6170692d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/CX-engine/expert-stats-api-sdk-php)

This package is a light PHP Wrapper / SDK for the Expert Stats API.

- [Installation](#installation)
- [Authentication](#authentication)
    - [Client Code Grant](#authentication-client-code-grant)
    - [Password Grant](#authentication-password-grant)
- [Usage](#usage)
    - [Requests](#usage-requests)
    - [Resources](#usage-resources)
    - [Responses](#usage-responses)
    - [Entities](#usage-entities)
    - [Pagination](#usage-pagination)
    - [Extending the SDK](#usage-extends)

Installation
------------

[](#installation)

This library requires PHP `>=8.2`.

You can install the package via composer:

```
composer require cx-engine/expert-stats-api-sdk-php

```

Authentication
--------------

[](#authentication)

Expert stats APIs supports OAuth2 for authentication. However, this package currently only supports the Password Grant authentication flow.

### Client Code Grant

[](#client-code-grant)

Not supported yet.

### Password Grant

[](#password-grant)

To connect using your usual Expert stats credentials, first initiate the `ExpertStatisticsConnector` class providing your instance URL, email and password :

```
use CXEngine\ExpertStats\ExpertStatisticsConnector;

$api = new ExpertStatisticsConnector(
    apiUrl: 'https://xp-stats-201.bluerock.tel/api',
    email: 'developers@bluerocktel.com',
    password: 'secret',
);
```

If the connector fails to retrive a Bearer token from the provided credentials, a `CXEngine\ExpertStats\Exceptions\AuthenticationException` will be thrown.

Usage
-----

[](#usage)

To query the API, you can either call each API [Endpoints requests](https://github.com/CX-engine/expert-stats-api-sdk-php/tree/main/src/Requests) individually, or make use of provided [Resources classes](https://github.com/CX-engine/expert-stats-api-sdk-php/tree/main/src/Resources) which groups the requests into clusters.

### Using Requests

[](#using-requests)

Using single requests is pretty straightforward. You can use the `call()` method of the `ExpertStatisticsConnector` class to send the desired request to the instance :

```
use CXEngine\ExpertStats\ExpertStatisticsConnector;
use CXEngine\ExpertStats\Requests;

$api = new ExpertStatisticsConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);

$response = $api->call(
  new Requests\Pbx3cxHosts\GetPbx3cxHostsRequest()
);
```

### Using Resources

[](#using-resources)

Using resources is a more convenient way to query the API. Each Resource class groups requests by specific API namespaces (Pbx3cxHost, Pbx3cxCall...).

```
use CXEngine\ExpertStats\ExpertStatisticsConnector;

$api = new ExpertStatisticsConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);

$response = $api->pbx3cxCall()->index(
    hostName: 'pbx01.acme.com',
);
```

Resources classes usually provide (but are not limited to) the following methods :

```
class NamespaceResource
{
    public function index(array $params = [], int $perPage = 20, int $page = 1): Response;
    public function show(int $id): Response;
    public function store(Entity $entity): Response;
    public function update(Entity $entity): Response;
    public function upsert(Entity $entity): Response;
    public function delete(int $id): Response;
}
```

> 👉 The `upsert()` method is a simple alias : it will call the `update()` method if the given entity has an id, or the `store()` method if not.

Each of those namespace resources can be accessed using the `ExpertStatisticsConnector` instance :

```
$connector = new ExpertStatisticsConnector(...);

$connector->pbx3cxHost(): Resources\Pbx3cxHostResource
$connector->pbx3cxCall(): Resources\Pbx3cxCallResource
...
```

If needed, it is also possible to create the desired resource instance manually.

```
use CXEngine\ExpertStats\ExpertStatisticsConnector;
use CXEngine\ExpertStats\Resources\Pbx3cxHostResource;

$api = new ExpertStatisticsConnector();
$resource = new Pbx3cxHostResource($api);

$hostData = $resource->show($hostId)->dtoOrFail();
$resource->upsert($hostData);
```

### Responses

[](#responses)

Weither you are using Requests or Resources, the response is always an instance of `Saloon\Http\Response` class. It provides some useful methods to check the response status and get the response data.

```
// Check response status
$response->ok();
$response->failed();
$response->status();
$response->headers();

// Get response data
$response->json(); # as an array
$response->body(); # as an raw string
$response->dtoOrFail(); # as a Data Transfer Object
```

You can learn more about responses by reading the [Saloon documentation](https://docs.saloon.dev/the-basics/responses#useful-methods), which this SDK uses underneath.

### Entities (DTO)

[](#entities-dto)

When working with APIs, dealing with a raw or JSON response can be tedious and unpredictable.

To make it easier, this SDK provides a way to transform the response data into a Data Transfer Object (DTO) (later called Entities). This way, you are aware of the structure of the data you are working with, and you can access the data using object typed properties instead of untyped array keys.

```
$response = $api->pbx3cxCall()->show(id: 92);

/** @var CXEngine\ExpertStats\Entities\Pbx3cxCall */
$call = $response->dtoOrFail();
```

Although you can use the `dto()` method to transform the response data into an entity, it is recommended to use the `dtoOrFail()` method instead. This method will throw an exception if the response status is not 2xx, instead of returning an empty DTO.

It is still possible to access the underlying response object using the `getResponse()` method of the DTO :

```
$entity = $response->dtoOrFail();   // \CXEngine\ExpertStats\Contracts\Entity
$entity->getResponse();             // \Saloon\Http\Response
```

> Learn more about working with Data tranfert objects on the [Saloon documentation](https://docs.saloon.dev/digging-deeper/data-transfer-objects).

The create/update/upsert routes will often ask for a DTO as first parameter :

```
use CXEngine\ExpertStats\Entities\Pbx3cxHost;

// create
$response = $api->pbx3cxHost()->store(
    host: new Pbx3cxHost(
        host_name: 'pbx01.acme.com',
        customer_account: 'CL0001',
    ),
);

$host = $response->dtoOrFail();

// update
$host->customer_account = 'CX0010';
$api->pbx3cxHost()->update($host);
```

### Pagination

[](#pagination)

On some index/search routes, the Expert stats API will use a pagination. If you need to iterate on all pages of the endpoint, you may find handy to use the connector's `paginate()` method :

```
$query = [
  'sort' => 'created_at',
];

# Create a PagedPaginator instance
$paginator = $api->paginate(new GetExamplesRequest($query));

# Iterate on all pages entities, using lazy loading for performance
foreach ($paginator->items() as $example) {
    $name = $example->name;
}
```

Read more about lazy paginations on the [Saloon documentation](https://docs.saloon.dev/installable-plugins/pagination#using-the-paginator).

### Extending the SDK

[](#extending-the-sdk)

You may easily extend the SDK by creating your own Resources, Requests, and Entities.

Then, by extending the `ExpertStatisticsConnector` class, add you new resources to the connector :

```
use CXEngine\ExpertStats\ExpertStatisticsConnector;

class MyCustomConnector extends ExpertStatisticsConnector
{
    public function defaultConfig(): array
    {
        return [
            'timeout' => 120,
        ];
    }

    public function customResource(): \App\Resources\CustomResource
    {
        return new \App\Resources\CustomResource($this);
    }
}

$api = new MyCustomConnector(XPSTATS_API_URL, XPSTATS_API_USERNAME, XPSTATS_API_PASSWORD);
$api->customResource()->index();
```

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance81

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~73 days

Total

15

Last Release

100d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d7c605c71ebef94596a6c0f89e40a62e0d685b052288fe8a0017a0378c85823f?d=identicon)[tgeorgel](/maintainers/tgeorgel)

![](https://avatars.githubusercontent.com/u/13690804?v=4)[Cyrille Georgel](/maintainers/cygeorgel)[@cygeorgel](https://github.com/cygeorgel)

---

Top Contributors

[![tgeorgel](https://avatars.githubusercontent.com/u/11785727?v=4)](https://github.com/tgeorgel "tgeorgel (17 commits)")

### Embed Badge

![Health badge](/badges/cx-engine-expert-stats-api-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/cx-engine-expert-stats-api-sdk-php/health.svg)](https://phpackages.com/packages/cx-engine-expert-stats-api-sdk-php)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.6M376](/packages/illuminate-redis)[codebar-ag/laravel-docuware

DocuWare integration with Laravel

1123.7k](/packages/codebar-ag-laravel-docuware)[illuminate/cookie

The Illuminate Cookie package.

244.6M137](/packages/illuminate-cookie)

PHPackages © 2026

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