Search by

Official PHP SDK for the BrickTrack LEGO price tracking API.

v0.1.0 2026-11-30 20:37 UTC

This package is auto-updated.

Last update: 2026-12-01 17:14:47 UTC


README

The official PHP SDK for the BrickTrack LEGO price tracking API.

Track LEGO set prices with a scheduled watchlist, price history and alerts.

The SDK exposes 9 methods, one per documented endpoint (with array-shape PHPDoc for static analysis), plus clearTargetPrice() and a generic request(). It sends requests through any PSR-18 client and uses Guzzle by default.

Requirements

  • PHP 8.1 or newer

Installation

composer require bricktrack/sdk

Get your API key

Sign up for BrickTrack or sign in, then copy your API key from the dashboard. The client reads the BRICKTRACK_API_KEY environment variable when no key is passed.

Quick start

<?php

require 'vendor/autoload.php';

use BrickTrack\Client;

$client = new Client(getenv('BRICKTRACK_API_KEY') ?: null);
$response = $client->searchSets(['query' => 'millennium falcon']);
print_r($response->data);

Parameter arrays use the names of the API reference. Unknown names throw a SerializationException; use request() for undocumented parameters.

HTTP methods

Each method uses the HTTP verb of its endpoint. GET and DELETE send parameters in the query string; POST and PATCH send them as a JSON body, except wait on /products/{id}/check, which stays in the query string. Null values are never sent; to remove a product's target price, call $client->clearTargetPrice($id), which sends PATCH /products/{id} with {"target_price": null}.

null values are omitted, false and 0 are sent, and lists repeat the parameter name.

Any endpoint

$response = $client->request('GET', '/account');

Errors

use BrickTrack\Exception\ApiException;

try {
    $client->searchSets(['query' => 'millennium falcon']);
} catch (ApiException $exception) {
    echo $exception->status, ': ', $exception->getMessage();
}
Exception When
ConfigurationException Missing API key, invalid options or unsupported method.
SerializationException A required parameter is missing, unknown or can't be sent.
TransportException Network failure or timeout.
ApiException Non-2xx status (status, errorCode, errorMessage, responseBody, rawResponse).
ResponseDecodingException A success response could not be decoded.

errorCode is the API's error.code, such as insufficient_credits, product_limit or not_found (null when the body has none).

All of them extend BrickTrack\Exception\BrickTrackException.

Retries

Requests are retried up to 3 times after a network error, a 408, 500, 502, 503 or 504. Other statuses, such as 400, 401, 402, 404 or 429, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a Retry-After header wins.

$client = new Client(null, ['max_retries' => 5, 'retry_delay' => 0.5]);
$client->searchSets(['query' => 'millennium falcon'], new RequestOptions(maxRetries: 0)); // one request without retries

Batch requests

batch() sends several calls with at most 10 requests in flight ($concurrency), through Guzzle's connection pool, and returns one BatchResult per call in input order. A failing call never stops the others. With a custom PSR-18 client the calls run one after another.

$inputs = ['millennium falcon', 'titanic', 'botanical'];
$calls = array_map(static fn(string $value): array => ['searchSets', ['query' => $value]], $inputs);

foreach ($client->batch($calls, concurrency: 5) as $result) {
    if ($result->ok()) {
        print_r($result->value->data);
    } else {
        echo $inputs[$result->index], ': ', $result->error->getMessage(), "\n";
    }
}
Constant Default Description
Client::DEFAULT_CONCURRENCY 10 Tasks run at the same time by batch
Client::DEFAULT_TIMEOUT 120.0 Request timeout (seconds)
Client::MAX_RETRIES 3 Retry attempts after a network error, a 408/5xx
Client::RETRY_BACKOFF_FACTOR 1.5 Exponential backoff multiplier
Client::DEFAULT_RETRY_DELAY 1.0 Delay before the first retry (seconds)

Options and custom HTTP clients

$client = new Client(null, [
    'timeout' => 60.0,               // seconds, default 120 (default Guzzle client only)
    'headers' => ['X-Trace' => 'abc'],
    'http_client' => $psr18Client,   // optional: any PSR-18 client
]);

Endpoints

9 methods, generated from the OpenAPI document.

Method HTTP Description
checkProduct() POST /products/{id}/check Asks for a check right away (1 credit), at most once per 5 minutes; earlier calls return the product unchanged. A paused product has to be…
deleteProduct() DELETE /products/{id} Removes the product and its price history.
getAccount() GET /account Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each…
getProduct() GET /products/{id} The product's latest state and every price read of the period, oldest first. The history covers every read of this set number on this marke…
getSetHistory() GET /history Every price BrickTrack read for a set number on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest an…
listProducts() GET /products Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with set_number (and marketplace) to k…
searchSets() GET /search LEGO sets matching a name, a theme or the start of a set number (up to 20, the biggest first), from BrickTrack's catalog of official sets,…
trackProduct() POST /products Adds a set number or a LEGO link to your watchlist. The first check runs in the background within seconds (checking is true until then): po…
updateProduct() PATCH /products/{id} Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target pr…

All BrickTrack SDKs

SDK Package Install
Node.js @bricktrack/sdk npm install @bricktrack/sdk
Python bricktrack pip install bricktrack
Go bricktrack-go go get github.com/bricktrackdev/bricktrack-go
.NET BrickTrack dotnet add package BrickTrack
Ruby bricktrack gem install bricktrack
PHP bricktrack/sdk composer require bricktrack/sdk
Java bricktrack-java build from source, see its README
CLI @bricktrack/cli npm install -g @bricktrack/cli
MCP server @bricktrack/mcp npx -y @bricktrack/mcp

Trademarks

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this software.

License

MIT — see LICENSE.