PHPackages                             lakion/sylius-api-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. lakion/sylius-api-php

ActiveLibrary[API Development](/categories/api)

lakion/sylius-api-php
=====================

Sylius API PHP client library

192.5k11[3 issues](https://github.com/Lakion/sylius-api-php/issues)[3 PRs](https://github.com/Lakion/sylius-api-php/pulls)PHP

Since Nov 16Pushed 8y ago9 watchersCompare

[ Source](https://github.com/Lakion/sylius-api-php)[ Packagist](https://packagist.org/packages/lakion/sylius-api-php)[ RSS](/packages/lakion-sylius-api-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Sylius API PHP client library
=============================

[](#sylius-api-php-client-library)

[![Build status...](https://camo.githubusercontent.com/9a84c438c31a5f511c2d6e8df3e2ceca2903aaf551b65ddd621dcb9b3f7e1e22/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f70726f6a6563742f4c616b696f6e2f73796c6975732d6170692d7068702e737667)](https://circleci.com/gh/Lakion/sylius-api-php) [![Code Quality](https://camo.githubusercontent.com/eb5f9b53a3022e71d03b103b647878b0144adad2a53d163a120290d9a19259d7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4c616b696f6e2f73796c6975732d6170692d7068702e737667)](https://scrutinizer-ci.com/g/Lakion/sylius-api-php/)

PHP client for RESTful Sylius API!

Usage
-----

[](#usage)

Initialize client with OAuth2 authentication and mapping

```
use GuzzleHttp\Client;
use Sylius\Api\Client as SyliusClient;
use Sylius\Api\Map\ArrayUriMap;
use Sylius\Api\ApiResolver;
use CommerceGuys\Guzzle\Oauth2\GrantType\RefreshToken;
use CommerceGuys\Guzzle\Oauth2\GrantType\PasswordCredentials;
use CommerceGuys\Guzzle\Oauth2\Oauth2Subscriber;

$oauth2Client = new Client([
    'base_url' => 'http://demo.sylius.org',
]);

$config = [
    'token_url' => 'oauth/v2/token',
    'client_id' => '1_demo_client',
    'client_secret' => 'secret_demo_client',
    'username' => 'api@example.com',
    'password' => 'api'
];

$token = new PasswordCredentials($oauth2Client, $config);
$refreshToken = new RefreshToken($oauth2Client, $config);

$oauth2 = new Oauth2Subscriber($token, $refreshToken);

// create sylius client
$syliusClient = SyliusClient::createFromUrl('http://demo.sylius.org/api/', $oauth2);

// initialize uri mapping for custom uris, all other uris are autogenerated (plural name of the resource, in accordance with RESTful API resource naming best practices)
$uriMap = new ArrayUriMap(
    [
        'product-variants' => 'products/{productId}/variants',
        'taxons'           => 'taxonomies/{taxonomyId}/taxons',
        'items'            => 'orders/{orderId}/items',
        'coupons'          => 'promotions/{promotionId}/coupons',
        'provinces'        => 'countries/{countryId}/provinces'
    ]
);
// initializer api resolver
$apiResolver = new ApiResolver($syliusClient, $uriMap);
```

If you use Symfony2 framework, you can also register some services, initialize Sylius API Client and inject it to other services.

```
parameters:
    app.http_client.sylius.base_url: 'http://local.sylius.dev/app_dev.php/'
    app.http_client.sylius.api_url: 'http://local.sylius.dev/app_dev.php/api/'
    app.http_client.sylius.token_url: 'oauth/v2/token'
    app.sylius_client.id: 1_demo_client
    app.sylius_client.secret: secret_demo_client
    app.sylius_client.username: api@example.com
    app.sylius_client.password: api
    app.sylius_taxonomy.uri: taxonomies

services:
    #Http client that is used to obtain OAuth2 token
    app.http_client.sylius_oauth:
        class: GuzzleHttp\Client
        arguments:
            - { base_url: %app.http_client.sylius.base_url% }
    #Password credentials that use http client to authenticate user with given data
    app.oauth2.grant_type.password_credentials:
        class: CommerceGuys\Guzzle\Oauth2\GrantType\PasswordCredentials
        arguments:
            - @app.http_client.sylius_oauth
            - { token_url: %app.http_client.sylius.token_url%, client_id: %app.sylius_client.id%, client_secret: %app.sylius_client.secret%, username: %app.sylius_client.username%, password: %app.sylius_client.password% }
    #Refresh token that use http client to refresh oauth2 token
    app.oauth2.grant_type.refresh_token:
        class: CommerceGuys\Guzzle\Oauth2\GrantType\RefreshToken
        arguments:
            - @app.http_client.sylius_oauth
            - { token_url: %app.http_client.sylius.token_url%, client_id: %app.sylius_client.id%, client_secret: %app.sylius_client.secret%, username: %app.sylius_client.username%, password: %app.sylius_client.password% }
    #Subscriber used by Sylius API Client to provide OAuth2 authentication
    app.oauth2.subscriber.sylius_api:
        class: CommerceGuys\Guzzle\Oauth2\Oauth2Subscriber
        arguments: [@app.oauth2.grant_type.password_credentials, @app.oauth2.grant_type.refresh_token]
    #Http client that is used to connect with Sylius API
    app.http_client.sylius_api:
        class: GuzzleHttp\Client
        arguments:
            - { base_url: '%app.http_client.sylius.api_url%', defaults: { auth: 'oauth2', subscribers: [@app.oauth2.subscriber.sylius_api] } }
    #Sylius API Client
    app.api_client.sylius:
        class: Sylius\Api\Client
        arguments: [@app.http_client.sylius_api]

    #Example API
    app.sylius_taxonomy.api:
        class: Sylius\Api\GenericApi
        arguments: [@app.api_client.sylius, %app.sylius_taxonomy.uri%]

    #Uri map with custom uris
    app.api_resolver.uri_map.sylius:
        class: Sylius\Api\Map\ArrayUriMap
        arguments:
            - { product-variants: 'products/{productId}/variants', taxons: 'taxonomies/{taxonomyId}/taxons', items: 'orders/{orderId}/items', coupons: 'promotions/{promotionId}/coupons', provinces: 'countries/{countryId}/provinces' }
    #Initialize Api resolver with uri map
    app.api_resolver.sylius:
        class: Sylius\Api\ApiResolver
        arguments: [@app.api_client.sylius, @app.api_resolver.uri_map.sylius]
```

**Get API for resource**

```
#Obtain api using api resolver
$taxonomiesApi = $apiResolver->getApi('taxonomies');
#or register it as a service and obtain it from container
$taxonomiesApi = $container->get('app.sylius_taxonomy.api');
$taxonsApi = $apiResolver->getApi('taxons');
```

**Create resource**

```
// right now because of translations you have to do it this way (will be changed in the nearest future to simply allow for ['name' => 'My taxonomy'])
$taxonomy = $taxonomiesApi->create(['translations' => ['en' => ['name' => 'My taxonomy']]]);
// for custom uris you have to specify uri parameters ('taxonomyId')
$taxon = $taxonsApi->create(['translations' => ['en' => ['name' => 'My taxon']]], ['taxonomyId' => $taxonomy['id']);
```

**Update resource**

```
$taxonomy = $taxonomiesApi->update($taxonomyId, ['translations' => ['en' => ['name' => 'My taxonomy updated']]]);
// for custom uris you have to specify uri parameters ('taxonomyId')
$taxon = $taxonsApi->update($taxonId, $taxonomy['translations' => ['en' => ['name' => 'My taxon' updated]]], ['taxonomyId' => $taxonomyId]);
```

**Get resource**

```
$taxonomy = $taxonomiesApi->get($taxonomyId);
// for custom uris you have to specify uri parameters ('taxonomyId')
$taxon = $taxonsApi->get($taxonId, ['taxonomyId' => $taxonomyId]);
```

**Get all resources**

- Get paginated resources

```
// you can getPaginated resources (it returns array)
$taxonomies = $taxonomiesApi->getPaginated($page, $limitPerPage);
$taxons = $taxonsApi->getPaginated($page, $limitPerPage, ['taxonomyId' => $taxonomyId]);
```

- Create paginator for resource

```
// you can create taxonomies paginator
$taxonomiesPaginator = $taxonomiesApi->createPaginator($limitPerPage);
// for custom uris you have to specify uri parameters ('taxonomyId'), rest is the same
$taxonsPaginator = $taxonsApi->createPaginator($limitPerPage, ['taxonomyId' => $taxonomyId]);
// returns array of elements for current page
$taxonomies = $taxonomiesPaginator->getCurrentPageResults();
// ... (do something with current page taxonomies)
// and go through all results
while ($taxonomiesPaginator->hasNextPage()) {
    $taxonomiesPaginator->nextPage();
    $taxonomies = $taxonomiesPaginator->getCurrentPageResults();
    // ... (do something with current page taxonomies)
}
```

- Get all resources

```
// getAll method gets all resources, so you have to be careful about the memory usage
$taxonomies = $taxonomiesApi->getAll();
// for custom uris you have to specify uri parameters ('taxonomyId')
$taxons = $taxonsApi->getAll(['taxonomyId' => $taxonomyId]);
```

**Delete resource**

```
// returns whether the deletion was successful or not
// for custom uris you have to specify uri parameters ('taxonomyId')
$trueOrFalse = $taxonsApi->delete($taxonId, ['taxonomyId' => $taxonomyId]);
$trueOrFalse = $taxonomiesApi->delete($taxonomyId);
```

Bug tracking
------------

[](#bug-tracking)

This component uses [GitHub issues](https://github.com/Lakion/sylius-api-php/issues). If you have found bug, please create an issue.

MIT License
-----------

[](#mit-license)

License can be found [here](https://github.com/Lakion/sylius-api-php/tree/master/LICENSE.md).

Authors
-------

[](#authors)

The library was originally created by:

- Michał Marcinkowski

See the list of [contributors](https://github.com/Lakion/sylius-api-php/graphs/contributors).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.2% 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/cf665c280ebb9c5f3a8589b92e1e29acef856558d3306a542580221d7e9b70d7?d=identicon)[michalmarcinkowski](/maintainers/michalmarcinkowski)

---

Top Contributors

[![michalmarcinkowski](https://avatars.githubusercontent.com/u/7572437?v=4)](https://github.com/michalmarcinkowski "michalmarcinkowski (47 commits)")[![Zales0123](https://avatars.githubusercontent.com/u/6212718?v=4)](https://github.com/Zales0123 "Zales0123 (3 commits)")[![bendavies](https://avatars.githubusercontent.com/u/625392?v=4)](https://github.com/bendavies "bendavies (1 commits)")

### Embed Badge

![Health badge](/badges/lakion-sylius-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/lakion-sylius-api-php/health.svg)](https://phpackages.com/packages/lakion-sylius-api-php)
```

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