vanilo/cloud-sdk

SDK for Vanilo Cloud API

0.5.1 2023-11-15 17:33 UTC

This package is auto-updated.

Last update: 2024-04-15 18:40:46 UTC


README

Tests Packagist version Packagist downloads StyleCI MIT Software License

This package provides a PHP SDK for interacting with the Vanilo Cloud REST API.

Vanilo Cloud PHP Code Sample

Installation

The minimum requirement of this package is PHP 8.1.

To install this library in your application, use composer:

composer require vanilo/cloud-sdk

Usage

Authentication

To connect to the Vanilo Cloud API, you'll need your Shop's URL, a client_id and a client_secret.

The following code returns an API client instance:

$api = VaniloCloud\ApiClient::for('https://your.v-shop.cloud')->withCredentials('client id', 'client secret');

Under the hood, the SDK will fetch auth tokens from the API in order to minimize the number of occasions when the client_id and client_secret are being sent over the wire.

To connect to the generic Sandbox environment use:

$api = VaniloCloud\ApiClient::sandbox();

Vanilo Cloud Sandbox is available at: https://sandbox.v-shop.cloud/
The sandbox database is reset every 30 minutes

Token Store

In order to effectively use the token authentication, and to avoid rate limiting exceptions, it's highly recommended to use a persistent token store.

When you have the APC extension installed and enabled, then you have nothing to do, everything is handled for you behind the scenes.

If you use this library in a Laravel Application, then the best is when you use the built-in Laravel Cache token store, that utilizes the configured cache for temporarily storing the auth tokens:

$api = VaniloCloud\ApiClient::for('https://your.v-shop.cloud')
    ->withCredentials('client id', 'client secret')
    ->useLaravelTokenStore();

Retrieve Raw Responses

If you need to obtain the raw HTTP response from the API, you need to call the rawGet, rawPost, etc methods:

$api = VaniloCloud\ApiClient::sandbox();
$api->rawGet('/taxonomies');
//=> Illuminate\Http\Client\Response {#2743
//     +cookies: GuzzleHttp\Cookie\CookieJar {#2725},
//     +transferStats: GuzzleHttp\TransferStats {#2765},

To obtain the contents of the API call, use json() method of the returned response:

$response = $api->rawGet('/taxonomies');
foreach ($response->json('data') as $taxonomy) {
    echo $taxonomy['name'];
}
// Category

Taxonomies

To fetch a taxonomy by id:

$api = VaniloCloud\ApiClient::sandbox();
$taxonomy = $api->taxonomy(1);
// => VaniloCloud\Models\Taxonomy
//     id: "1",
//     name: "Category",
//     slug: "category",
//     created_at: "2022-12-06T16:23:34+00:00",
//     updated_at: "2023-01-13T08:03:29+00:00"

Products