PHPackages                             liamja/cex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. liamja/cex

ActiveProject[API Development](/categories/api)

liamja/cex
==========

Client for CeX UK's internal API.

44PHP

Since Sep 2Pushed 7y ago2 watchersCompare

[ Source](https://github.com/liamja/cex)[ Packagist](https://packagist.org/packages/liamja/cex)[ RSS](/packages/liamja-cex/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

CeX API Client
==============

[](#cex-api-client)

PHP client for CeX UK's internal Ajax API.

This client was created from reverse engineering the Ajax responses when browsing the website, so it assumes a lot.

License
-------

[](#license)

Licensed under MIT - see LICENSE.md for more info.

Installation
------------

[](#installation)

```
composer require liamja/cex
```

Testing
-------

[](#testing)

```
vendor/bin/phpunit
```

Getting Started
---------------

[](#getting-started)

Create a new instance of the CeX Client:

```
$cex = new CexClient();
```

Searching for Products / Boxes
------------------------------

[](#searching-for-products--boxes)

Individual products are referred to as *Boxes*.

```
// Specify a new set of search parameters.
$searchParameters = new SearchParameters();
$searchParameters->setSearchTerm('Super Mario Bros');

// Search for boxes that match our parameters.
$boxes = $cex->searchBoxes($searchParameters);

// CexClient::searchBoxes() returns an array of \Liamja\Cex\Models\Box
foreach ($boxes as $box) {
    // Get the box's unique ID.
    echo $box->boxId;          // 045496901738

    // Get the box's name.
    echo $box->boxName;        // New Super Mario Bros. Wii

    // Get the category the box belongs to.
    echo $box->categoryName;   // Wii Software

    // Get the cash price.
    echo $box->cashPrice;      // 5.00

    // Get the trade-in / exchange price.
    echo $box->exchangePrice;  // 8.00

    // Get the sale price.
    echo $box->salePrice;      // 12.00
}
```

Searching for Stores
--------------------

[](#searching-for-stores)

To search for stock near a location, you'll first need to search for the store.

The API will return a set of stores closest to a given latitude and longitude.

Geocoding isn't in the scope of this package, but you can lookup a location's approximate latitude and longitude using a geocoding service such as :

```
// Set up a new Guzzle client solely for geocoding.
$geocodeClient = new \GuzzleHttp\Client([
    'base_uri' => 'https://geocode.xyz/',
]);

$response = $geocodeClient->get('Manchester, UK' . '?json=1');
$results  = json_decode($response->getBody()->getContent());

// Use the geocoding results to find stores closest to Manchester.
$stores = $cex->nearestStores($results->latt, $results->longt);
```

To find stores closest to a longitude and latitude:

```
// First, you'll need the lat/long of the location you want to search.
$latitude  = 52.62343240000001;
$longitude = 1.3077290999999605;

// Search for stores closest to a given location.
$stores = $cex->nearestStores($latitude, $longitude);

// CexClient::nearestStores() returns an array of \Liamja\Cex\Models\NearestStore
foreach ($stores as $store) {
    // Get the store's unique ID.
    echo $store->storeId;                   // 168

    // Get the store's name.
    echo $stores->storeName;                // Norwich

    // How far away the store is from the given location, in miles.
    echo $stores->distance;                 // 0.47

    // Opening days and times.
    echo $box->timings['open']['monday'];   //  9:00
    echo $box->timings['close']['friday'];  // 18:00
}
```

Get All Stores
--------------

[](#get-all-stores)

```
$stores = $cex->getStores();

// CexClient::getStores() returns an array of \Liamja\Cex\Models\Store
foreach ($stores as $store) {
    // Get the store's unique ID.
    echo $store->storeId;     // 168

    // Get the store's name.
    echo $stores->storeName;  // Norwich

    // Get the store's region.
    echo $stores->storeName;  // East Anglia
}
```

### Searching for Products at a Given Store

[](#searching-for-products-at-a-given-store)

```
// Search for stores closest to a given location.
$stores = $cex->nearestStores(52.62343240000001, 1.3077290999999605);

// Get the nearest store's ID.
$storeId = $stores[0]->storeId

// Search for stocked Battletoads at our nearest store.
$searchParameters = new SearchParameters();
$searchParameters
    ->setSearchTerm('Battletoads')
    ->setStoreId($storeId)
    ->isInStock();

$boxes = $cex->searchBoxes($searchParameters);
```

Handling Errors
---------------

[](#handling-errors)

If the API returns an error, a FailureException will be thrown:

```
try {
    $boxes = $cex->searchBoxes($searchParameters);
} catch (\Liamja\Cex\FailureException $e) {
    echo $e->getMessage();   // "Missing search text"
    echo $e->getCode();      //
    echo $e->getMoreInfo();  // []
}
```

Cheatsheet
----------

[](#cheatsheet)

```
$cex = new CexClient();

// Search for 'Battleloads' titles that are in stock.
$searchParameters = new SearchParameters();
$searchParameters
    ->setSearchTerm('Battletoads')
    ->isInStock();

$boxes = $cex->searchBoxes($searchParameters);

var_dump($boxes);

// Search using their predictive search (seems better at sorting by relevancy.)
$searchParameters = new SearchParameters();
$searchParameters->setSearchTerm('Super Mario Bros');

$results = $cex->predictiveSearch($searchParameters);

var_dump($results);

// Search for stores closest to a given location.
$stores = $cex->nearestStores(52.62343240000001, 1.3077290999999605);

var_dump($stores);

// Show all stores in the country.
$stores = $cex->getStores();

var_dump($stores);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/37d06715b6487a154314e32970d1a781e53a6f686de2430dcf0412f3f6db4afe?d=identicon)[liamja](/maintainers/liamja)

---

Top Contributors

[![liamja](https://avatars.githubusercontent.com/u/962914?v=4)](https://github.com/liamja "liamja (25 commits)")

---

Tags

api-clientcomposercomposer-packagephpphp-libraryphp7rest-clientshopping

### Embed Badge

![Health badge](/badges/liamja-cex/health.svg)

```
[![Health](https://phpackages.com/badges/liamja-cex/health.svg)](https://phpackages.com/packages/liamja-cex)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
