PHPackages                             batteryincluded/batteryincluded-php-sdk - 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. batteryincluded/batteryincluded-php-sdk

ActiveLibrary[API Development](/categories/api)

batteryincluded/batteryincluded-php-sdk
=======================================

The official php sdk for batteryincluded.ai

0.7.3(1mo ago)19.0k—4.7%3[2 issues](https://github.com/eiling-io/batteryincluded-php-sdk/issues)[1 PRs](https://github.com/eiling-io/batteryincluded-php-sdk/pulls)1MITPHPPHP ^8.2CI passing

Since Nov 21Pushed 1mo agoCompare

[ Source](https://github.com/eiling-io/batteryincluded-php-sdk)[ Packagist](https://packagist.org/packages/batteryincluded/batteryincluded-php-sdk)[ RSS](/packages/batteryincluded-batteryincluded-php-sdk/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (10)Dependencies (3)Versions (27)Used By (1)

[![Alt](https://camo.githubusercontent.com/3630bd1c35a157b38c290c335d40986c4b94233111bd40370b039bdb7192fd51/68747470733a2f2f7265706f62656174732e6178696f6d2e636f2f6170692f656d6265642f393663653236393135313664396136613238323165336236376335323830303539656665383962322e737667 "Repobeats analytics image")](https://camo.githubusercontent.com/3630bd1c35a157b38c290c335d40986c4b94233111bd40370b039bdb7192fd51/68747470733a2f2f7265706f62656174732e6178696f6d2e636f2f6170692f656d6265642f393663653236393135313664396136613238323165336236376335323830303539656665383962322e737667)[![Discord](https://camo.githubusercontent.com/e2bff71023ee0efe2e98a945d5fad761bec25bee9cc716d041d1c54c275991c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446973636f72642d4a6f696e2532305365727665722d3732383944413f7374796c653d666f722d7468652d6261646765266c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465)](https://discord.gg/fAbqNjwG)

[![Latest Stable Version](https://camo.githubusercontent.com/ec7f96ba8bdf8c795742ae219782170c6fb5aaedcdb492b3625feba431aa0f80/68747470733a2f2f706f7365722e707567782e6f72672f62617474657279696e636c756465642f62617474657279696e636c756465642d7068702d73646b2f762f737461626c65)](https://packagist.org/packages/batteryincluded/batteryincluded-php-sdk) [![Packagist](https://camo.githubusercontent.com/160e9eb64a0cb8dc1a2bad8cad496d843093c352f982af8532cb94ba2cebcd8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62617474657279696e636c756465642f62617474657279696e636c756465642d7068702d73646b2e737667)](https://packagist.org/packages/batteryincluded/batteryincluded-php-sdk)

batteryincluded-php-sdk
=======================

[](#batteryincluded-php-sdk)

The SDK is licensed under the [MIT License](LICENSE). Feel free to contribute!

Using the SDK
-------------

[](#using-the-sdk)

The [API documentation](https://www.postman.com/batteryincluded/core/overview) provides all information about the available endpoints.

### Install &amp; Integrate the SDK into your Project

[](#install--integrate-the-sdk-into-your-project)

The SDK requires a PHP version of 8.2 or higher. The recommended way to install the SDK is through [Composer](http://getcomposer.org).

```
composer require batteryincluded/batteryincluded-php-sdk
```

### Usage

[](#usage)

You can find for every implemented api action an example file in the examples directory.

### Extending ProductBaseDto with Custom Fields

[](#extending-productbasedto-with-custom-fields)

`ProductBaseDto` covers the standard product fields (`name`, `description`, `ordernumber`, `price`, `instock`, `rating`, etc.). To sync additional, shop-specific fields (e.g. `keywords`, `material`, `color`), extend the class and override `jsonSerialize()`.

**1. Create a subclass**

```
use BatteryIncludedSdk\Dto\ProductBaseDto;

class ProductDto extends ProductBaseDto
{
    private ?string $keywords = null;

    public function setKeywords(string $keywords): void
    {
        $this->keywords = $keywords;
    }

    private function getKeywords(): ?string
    {
        return $this->keywords;
    }

    public function jsonSerialize(): array
    {
        $jsonDto = [
            'keywords' => $this->getKeywords(),
        ];

        return array_merge_recursive(
            parent::jsonSerialize(),
            ['_' . $this->getType() => array_filter($jsonDto, static fn($value) => $value !== null)]
        );
    }
}
```

The custom fields must be nested under the `_PRODUCT` key (i.e. `'_' . $this->getType()`). `array_merge_recursive` merges them into the parent payload without overwriting the base fields. `array_filter` strips `null` values so only populated fields are sent.

**2. Populate and sync**

```
use BatteryIncludedSdk\Client\ApiClient;
use BatteryIncludedSdk\Client\CurlHttpClient;
use BatteryIncludedSdk\Service\SyncService;

$product = new ProductDto('1');
$product->setName('iPhone 15 Pro');
$product->setOrdernumber('AP-001-128GB');
$product->setPrice(1199.00);
$product->setInstock(42);
$product->setKeywords('smartphone apple ios');

$apiClient = new ApiClient(
    new CurlHttpClient(),
    'https://api.batteryincluded.io/api/v1/collections/',
    $collection,
    $apiKey
);

$syncService = new SyncService($apiClient);
$result = $syncService->syncFullElements($product);
```

Pass multiple products as separate arguments to `syncFullElements()` to sync them in a single request. A full working example is available in [`examples/extension/product.php`](examples/extension/product.php).

### Mixed Index: Products and Blog Posts in a Single Collection

[](#mixed-index-products-and-blog-posts-in-a-single-collection)

A single collection can hold multiple document types. Each document carries a `type` field and a type-scoped data key (e.g. `_PRODUCT`, `_BLOG`), so the index stores heterogeneous content while still allowing type-specific searches.

**1. Sync products and blogs together**

```
use BatteryIncludedSdk\Client\ApiClient;
use BatteryIncludedSdk\Client\CurlHttpClient;
use BatteryIncludedSdk\Dto\BlogBaseDto;
use BatteryIncludedSdk\Dto\ProductBaseDto;
use BatteryIncludedSdk\Service\SyncService;

$product = new ProductBaseDto('1');
$product->setName('iPhone 15 Pro');
$product->setPrice(1199.00);

$blog = new BlogBaseDto('1');
$blog->setTitle('Top 5 Smartphones 2024');
$blog->setAuthor('Jane Doe');
$blog->setPublishedAt('2024-06-01');

$apiClient = new ApiClient(
    new CurlHttpClient(),
    'https://api.batteryincluded.io/api/v1/collections/',
    $collection,
    $apiKey
);

$syncService = new SyncService($apiClient);
$syncService->syncFullElements($product, $blog);
```

Each document is stored with a prefixed ID (`PRODUCT-1`, `BLOG-1`) and a `type` field, so documents from different types never collide even when their identifiers overlap.

**2. Search all types at once**

```
use BatteryIncludedSdk\Shop\BrowseSearchStruct;
use BatteryIncludedSdk\Shop\BrowseService;

$searchStruct = new BrowseSearchStruct();
$searchStruct->setQuery('iPhone');

$browseService = new BrowseService($apiClient);
$result = $browseService->browse($searchStruct); // returns products AND blogs
```

**3. Filter to a specific type**

Pass `type` as a filter key to restrict results to only products or only blog posts:

```
// Only products
$searchStruct = new BrowseSearchStruct();
$searchStruct->setQuery('iPhone');
$searchStruct->addFilter('type', 'PRODUCT');

// Only blog posts
$searchStruct = new BrowseSearchStruct();
$searchStruct->setQuery('iPhone');
$searchStruct->addFilter('type', 'BLOG');
```

**4. Access type-specific fields in the result**

Each hit contains the type-scoped key, so check `type` first to access the right payload:

```
foreach ($result->getHits() as $hit) {
    $document = $hit['document'];

    if ($document['type'] === 'PRODUCT') {
        $data = $document['_PRODUCT'];
        echo $data['name'] . ' – ' . $data['price'] . ' €';
    } elseif ($document['type'] === 'BLOG') {
        $data = $document['_BLOG'];
        echo $data['title'] . ' by ' . $data['author'];
    }
}
```

A full working example is available in [`examples/sync/sync_full_product_and_blogs.php`](examples/sync/sync_full_product_and_blogs.php).

Community
---------

[](#community)

Join our community on [Discord](https://discord.gg/fAbqNjwG) to ask questions, give feedback, or connect with other developers.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance70

Regular maintenance activity

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.5% 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 ~10 days

Recently: every ~24 days

Total

18

Last Release

51d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4624237?v=4)[Thomas Eiling](/maintainers/teiling88)[@teiling88](https://github.com/teiling88)

---

Top Contributors

[![teiling88](https://avatars.githubusercontent.com/u/4624237?v=4)](https://github.com/teiling88 "teiling88 (82 commits)")[![michaelroling1310](https://avatars.githubusercontent.com/u/157351053?v=4)](https://github.com/michaelroling1310 "michaelroling1310 (2 commits)")[![migo315](https://avatars.githubusercontent.com/u/13180135?v=4)](https://github.com/migo315 "migo315 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/batteryincluded-batteryincluded-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/batteryincluded-batteryincluded-php-sdk/health.svg)](https://phpackages.com/packages/batteryincluded-batteryincluded-php-sdk)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k16](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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