Source Code
<?php
require_once '../vendor/autoload.php';
use Swagger\Client\Api\ProductApi;
use Swagger\Client\ApiException;
// PARAMETERS
$offset = clear('offset');
$limit = clear('limit');
$name = clear('name');
$published = clear('published');
$update_date = formatDate('update_date');
$product_category = null;
$deleted = false;
$ids = null;
// ADD WILDCARD
if (!empty($name)) {
$name .= '%';
}
// E2E ACCESS KEYS
$client = new GuzzleHttp\Client([
'headers' => [
'api_key' => 'JHSV2V6KyqcbxvMHshRlPfunJymVt7GDfXyoK229o=',
'company_key' => 'E2ELIVE',
]
]);
try {
// SEARCH PRODUCTS
$api = new ProductApi($client);
$result = $api->productList(
$offset,
$limit,
$name,
$published,
$update_date,
$product_category,
$deleted,
$ids
);
header('Content-Type: application/json; charset=utf-8');
echo $result->__toString();
} catch (Exception $e) {
http_response_code($e->getCode());
$msg = $e instanceof ApiException ? $e->getResponseBody() : $e->getMessage();
if (!empty($msg)) {
echo $msg;
}
}
function clear($field)
{
return empty($_REQUEST[$field]) ? null : $_REQUEST[$field];
}
function formatDate($field)
{
$date = clear($field);
if (!empty($date)) {
$date = DateTime::createFromFormat('Y-m-d', $date);
$date = $date->format(DateTime::ISO8601);
}
return $date;
}