PHP code example of lightspeedhq / ls-ecom-guzzle
1. Go to this page and download the library: Download lightspeedhq/ls-ecom-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-ecom-guzzle example snippets
ghtspeedHQ\Ecom\EcomClient;
$cluster = 'us1'; // eu1 or us1
$language = 'us'; // Shop language
$key = 'xxxx'; // API key
$secret = 'xxxx'; // API secret
$client = new EcomClient($cluster, $language, $key, $secret);
// GET request with some URL paramters.
$query = ['since_id', 1];
$response = $client->get('customers', ['query' => $query]);
$customers = json_decode($response->getBody(), true)['customers'];
echo '<pre>';
echo '<h3>GET Test</h3>';
var_dump($customers[0]);
echo '</pre>';
// POST request to create a discount code
$payload = [
'discount' => [
'discount' => 5,
'isActive' => true,
'minumumAmount' => 50,
'applyTo' => 'productscategories',
'endDate' => '2018-01-01',
'type' => 'percentage',
'code' => '5PERCENT',
'startDate' => '2017-01-01',
'usageLimit' => 9999,
]
];
$response = $client->post('discounts', ['json' => $payload]);
echo '<h3>POST Test</h3>';
echo '<pre>';
var_dump(json_decode($response->getBody(), true));
echo '</pre>';