vanilo / cloud-sdk
SDK for Vanilo Cloud API
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.4
- illuminate/collections: >8
- illuminate/http: ^8.22.1|^9.0|^10.0
- nesbot/carbon: ^2.53.1
Requires (Dev)
- ext-apcu: *
- illuminate/cache: >8
- orchestra/testbench: ^6.8|^7.0|^8.0
- phpunit/phpunit: ^9.5|^10.0
Suggests
- ext-apcu: Required to use the ApcTokenStore
- illuminate/cache: Required for the LaravelTokenStore ^8.0
README
This package provides a PHP SDK for interacting with the Vanilo Cloud REST API.
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
andclient_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"