PHP code example of lightspeedhq / ls-retail-guzzle
1. Go to this page and download the library: Download lightspeedhq/ls-retail-guzzle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lightspeedhq / ls-retail-guzzle example snippets
ightspeedHQ\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 '<h3>GET Test</h3>';
echo '<pre>';
var_dump($items['ItemShops']['ItemShop'][0])
echo '</pre>'
// POST request to create an Item
$payload = [
'description' => 'Rest Test',
'Prices' => [
'ItemPrice' => [
'amount' => 100,
'useType' => 'Default'
]
]
];
$response = $client->post('Item', ['json' => $payload]);
echo '<h3>POST Test</h3>';
echo '<pre>';
var_dump(json_decode($response->getBody(), true));
echo '</pre>';
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.