PHP SDK for Eusi, an API-first CMS that is user-friendly, beautifully designed and easy to use.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Official PHP SDK for EUSI an API-first CMS

Table of contents
  1. Getting started
  2. Authorization
    • Access Token
    • Login/Register user
  3. Fetching taxonomy
  4. Fetching content
    • Synchronous
    • Asynchronous
    • Filtering
  5. Forms
  6. Extra

Getting Started

First install our package with composer by calling composer require jsguru-io/eusi-php-sdk;

If you are making a custom script don't forget to require composer autoload.php, othwerwise if you're using some framework this is probably already done for you.

    require 'vendor/autoload.php';
    $eusi = new Eusi\Eusi([
        'bucket_id' => 'xxx-xxx-xxx-xxx',
        'bucket_secret' => 'agent-007'

You can put yout Bucket ID and Bucket SECRET in an .env file as well. Then you can initialize Eusi without providing them through constructor.

$eusi = new Eusi\Eusi();


To get an access token call authorize. If you have previously stored the token somewhere you can provide it as an argument as well.

$bucket = $eusi->authorize()->bucket();

// or

$bucker = $eusi->authorize(new AccessToken('xxx-xxx-xxx'))->bucket();

To get a higher level access token login a user.

$bucket = $eusi->authorize()->bucket();
$bucket->login('', '******');
$bucket->register('', '******');

Fetching taxonomy


Fetching content

Fetch one item
$item = $bucket->fetchItem($keyOrId);
$items = $bucket->items()->fetch(10);
$items = $bucket->items()->async()->fetch(10)->unwrap();
$items = $bucket->items()->async()->fetch(10)->then(function ($response) {
    // Do something else
})->then(function ($response) {
    // Do something else again
// Fails silently
$items = $items->unwrap();
// Throws exception
$items = $items->unwrap(false);
Filtering content

For your convenience we made a query builder, it might be familiar to you from Laravel. All of the filtering methods are chainable, but some of them might not work together. All of the methods accept either multiple $value arguments or an array of values.

    $items = $bucket->items()
        ->where('', 'like', '%rasmus%')
        ->where('elem.elem_name', 'in', 'foo', 'bar')
        ->where('elem.elem_date', 'btw', ['2017-01-01', '2018-01-01'])

Here is a full list of helper methods for reference.

$items = $bucket->items()
    ->whereTitleBetween(... $values)
    ->whereTaxBetween(... $values)
    ->whereModelBetween(... $values)
    ->whereTaxPathBetween($key,... $values)
    ->whereElementNotIn($key,... $values)
    ->whereElementLike($key,... $values)
    ->whereElementBetween($key,... $values)

Or you can filter with the "low-level" fetch method building the query string manually

        '[$like]' => '%foo'

List of supported operators and their user friendly aliases used in ->where():

 'like' => '[$like]',
 '~' => '[$like]',
 '>' => '[$gt]',
 '>=' => '[$gte]',
 '<' => '[$lt]',
 '<=' => '[$lte]',
 '!=' => '[$ne]',
 'in' => '[$in]',
 'between' => '[$between]',
 'btw' => '[$between]'


    $form = $bucket->form('id-or-key');
        'field_name_1' => 'foo',
        'field_name_2' => 'bar'
        'field_name_1' => 'foo',
        'field_name_2' => 'bar'


Any method that has a suffix 'Raw' returns a PSR-7 compliant Response object, otherwise your Response will be a Eusi\Utils\Json object.

Eusi\Utils\Json is a convenience class that implements ArrayAccess interface, so you can access the server response either as object or array.

    $response = $bucket->items()->whereTitle('Rasmus')->fetch(1);
    $rasmus = $response['data'][0];
    // or
    $rasmus = $response->data[0];

All async methods return an object implementing Eusi\Delivery\AsyncInterface.

That is a thin wrapper around Guzzle PSR-7 compliant Promises which allow us to manipulate the response and maintain a consistent API for both synchronous and asynchronous requests.

All SDK exceptions are thrown as application/json response.