RetailClient for Lightspeed Retail
The class is an extension of the Guzzle 6 PHP HTTP Client for use with the Lightspeed Retail API., (*1)
It works the same way as the standard Guzzle Client, but takes care of refreshing access tokens and rate limiting., (*2)
This package was created for demonstration purposes and comes with no waranty., (*3)
Installation
Use this commmand to install with Composer:, (*4)
$ composer require lightspeedhq/ls-retail-guzzle:~1.0
Alternatively, you can add these lines to your composer.json
file:, (*5)
"require": {
"lightspeedhq/ls-retail-guzzle": "~1.0"
}
Usage Example
<?php
require 'vendor/autoload.php';
use LightspeedHQ\Retail\RetailClient;
// Replace these with your own values for testing.
// API tokens and client credentials should not be stored in your code!
$account_id = XXXXX;
$refresh_token = '****';
$client_id = '****';
$client_secret = '****';
$client = new RetailClient($account_id, $refresh_token, $client_id, $client_secret);
// GET request with some URL paramters. We'll get the first ItemShop
// from this item and dump it.
$query = [
'load_relations' => '["ItemShops"]',
'description' => '~,%test%',
'limit' => 1
];
$response = $client->get('Item', ['query' => $query]);
$items = json_decode($response->getBody(), true)['Item'];
echo '
GET Test
';
echo '
';
var_dump($items['ItemShops']['ItemShop'][0])
echo '
'
// POST request to create an Item
$payload = [
'description' => 'Rest Test',
'Prices' => [
'ItemPrice' => [
'amount' => 100,
'useType' => 'Default'
]
]
];
$response = $client->post('Item', ['json' => $payload]);
echo '
POST Test
';
echo '
';
var_dump(json_decode($response->getBody(), true));
echo '
';