PHP
These use PHP’s built-in curl extension - no Composer dependencies required.
A small client
Section titled “A small client”<?php
const BASE_URL = "https://dev-api.theprioryshop.co.uk";$apiKey = getenv("EPOS_API_KEY"); // never hardcode this
class EposApiException extends Exception { public string $code; public string $requestId; public function __construct(string $code, string $requestId, string $message) { parent::__construct($message); $this->code = $code; $this->requestId = $requestId; }}
function epos_get(string $path, array $query = []): array { global $apiKey; $url = BASE_URL . $path . (count($query) ? "?" . http_build_query($query) : ""); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $apiKey"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $raw = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
$body = json_decode($raw, true); if ($status >= 400) { $error = $body["error"]; throw new EposApiException($error["code"], $error["requestId"], $error["message"]); } return $body;}List products
Section titled “List products”$products = epos_get("/v1/catalog/products", ["pageSize" => 20]);echo $products["total"] . " products total, " . count($products["rows"]) . " on this page\n";Get a single product
Section titled “Get a single product”$product = epos_get("/v1/catalog/products/clx1product000001");List categories, promotions, inventory stock
Section titled “List categories, promotions, inventory stock”$categories = epos_get("/v1/catalog/categories");$promotions = epos_get("/v1/catalog/promotions");$stock = epos_get("/v1/inventory/stock", ["storeId" => "clx1store0000001"]);Handle an error
Section titled “Handle an error”try { epos_get("/v1/catalog/products/does-not-exist");} catch (EposApiException $err) { if ($err->code === "not_found") { echo "No such product\n"; } elseif ($err->code === "rate_limited") { echo "Back off and retry - see Rate Limits\n"; } else { echo "EPOS API error {$err->code} (request {$err->requestId})\n"; }}Paginate through every product
Section titled “Paginate through every product”function all_products(): Generator { $page = 1; while (true) { $result = epos_get("/v1/catalog/products", ["pageSize" => 100, "page" => $page]); foreach ($result["rows"] as $row) { yield $row; } if ($page >= $result["totalPages"]) { break; } $page += 1; }}
foreach (all_products() as $product) { // ...}Incremental sync with updatedSince
Section titled “Incremental sync with updatedSince”$since = $lastSyncedAt->format("Y-m-d\TH:i:s.v\Z");$changed = epos_get("/v1/catalog/products", ["updatedSince" => $since]);See Catalog Sync for the full pattern.