Build and prove your lab integration with generated albums and the real API.
Test mode gives your lab its own resettable set of generated album exports. It uses the same API, download signing, event feed and webhook delivery as live mode. Test activity does not touch photographers' albums, create billing usage or send photographer or lab notifications.
Use https://api.spreadu.com/api/print-lab/v1 in both modes. A key beginning
spreadu_lab_test_ selects test mode; a live key begins spreadu_lab_.
GET /me returns mode, and authenticated responses include Spreadu-Mode.
Test keys cannot read live exports, and live keys cannot run the simulator.
You need an active lab, permission to manage its API settings, curl, jq and uuidgen.
In Lab Portal → Settings → API, switch to Test and create a key with
Full access, including sandbox:manage and webhooks:manage.
Copy it while it is visible. If Test mode is unavailable, the sandbox rollout
has not been enabled for your lab yet. Live API access is a separate admin grant.
export API="https://api.spreadu.com/api/print-lab/v1"
export SPREADU_KEY="<your-test-key>"
curl --fail-with-body -sS "$API/me" \
-H "Authorization: Bearer $SPREADU_KEY" | jq '{mode, lab, key}'Check for "mode": "test" before continuing.
Choose a unique command ID. Reuse it only when retrying this same request.
The simulator returns the stable reference and revision immediately; generation
runs asynchronously and publishes export.available when the files are ready.
export COMMAND_ID="$(uuidgen)"
CREATED=$(curl --fail-with-body -sS -X POST "$API/sandbox/exports" \
-H "Authorization: Bearer $SPREADU_KEY" \
-H "Idempotency-Key: $COMMAND_ID" \
-H "Content-Type: application/json" \
-d '{"scenario":"spreads-jpg"}')
export REFERENCE=$(printf '%s' "$CREATED" | jq -r '.reference')
printf '%s\n' "$CREATED" | jqRepeat that request with the same body and command ID. The response must identify
the same export. A different body or operation with the same ID returns
IDEMPOTENCY_CONFLICT.
Read the export until downloadableRevision is 1. Wait briefly between reads;
PREPARING is an expected state, not a failed download.
curl --fail-with-body -sS "$API/exports/$REFERENCE" \
-H "Authorization: Bearer $SPREADU_KEY" | jq
curl --fail-with-body -sS "$API/exports?downloadable=true" \
-H "Authorization: Bearer $SPREADU_KEY" | jqRequest all production files and packages for the exact revision:
curl --fail-with-body -sS -X POST "$API/exports/$REFERENCE/download-urls" \
-H "Authorization: Bearer $SPREADU_KEY" \
-H "Content-Type: application/json" \
-d '{"revision":1}' > download-urls.json
jq '.files[] | {filename: .file.filename, sha256: .file.checksumSha256, url}' download-urls.jsonEach entry contains file metadata and its url. Download every entry and compare
its byte size and SHA-256 with file.sizeBytes and file.checksumSha256.
For a quick inspection of the first file:
curl --fail -sS "$(jq -r '.files[0].url' download-urls.json)" -o first-file
sha256sum first-file # macOS: shasum -a 256 first-file
jq -r '.files[0].file.checksumSha256' download-urls.jsonUse the reference integration to download and verify the entire revision automatically. Record the receipt only after every file matches:
curl --fail-with-body -sS -X PUT "$API/exports/$REFERENCE/receipt" \
-H "Authorization: Bearer $SPREADU_KEY" \
-H "Content-Type: application/json" -d '{"revision":1}'A second receipt returns changed: false and the original receivedAt.
The feed includes export.requested, export.available and export.received
after sequencing. Keep the returned nextCursor as a string and pass it to the
next call, including after an empty page:
curl --fail-with-body -sS "$API/events" \
-H "Authorization: Bearer $SPREADU_KEY" > events.json
CURSOR=$(jq -r '.nextCursor' events.json)
curl --fail-with-body -sS "$API/events?after=$CURSOR&wait=5" \
-H "Authorization: Bearer $SPREADU_KEY" | jqSave your cursor only after safely processing the returned events. Do not use the order in which webhooks arrive as the order of the feed.
Expose a local receiver with a public HTTPS tunnel, following the next section.
In Test mode, add its URL in the portal's webhook settings, subscribe to * and
save the one-time whsec_... secret in the receiver. Send a test ping to check
the signature, then create another test export to receive real export events.
A ping has no event-feed cursor and does not replace handling a real event.
Open the delivery in the portal inspector. Its request body is exactly what was signed; the response shows your receiver's status, a bounded body preview and duration. Resend keeps the event identity and body, with a fresh timestamp and signature. Test endpoints retain captures for their last 20 deliveries; live endpoints retain status metadata.
All scenarios use labelled test patterns rather than photographs. Files identify the spread or page, revision and part, with production guides and colour bars. Frozen pixel dimensions in the export are authoritative. The manifest, ZIP and order summary follow the normal production format.
| Scenario | What it simulates | Events and what to try next |
|---|---|---|
spreads-jpg | Ten light JPG spreads, sRGB, 300 DPI. Default if omitted. | export.requested, then export.available. Download every file, verify checksums and record a receipt. |
pages-pdf | PDF output with a combined PDF and individual page files. | Requested, then available. Handle COMBINED_PDF packages and page files without assuming JPGs. |
cover-and-inner | A cover with a spine and inner spreads. | Requested, then available. Route COVER and INNER parts independently and inspect the spine guide. |
with-order | An order number, external ID and two printed copies. | Requested, then available. Read current order fields and each revision's frozen order; copies are not album length. |
print-size | Full-size files for throughput checks. | Requested, then available. Measure download time and exercise resumable downloads. Read sizeBytes; compressed sizes can vary. |
correction | Revision 1 is made available, then revision 2 automatically replaces it. | Requested, available, withdrawn, requested, available. Stop producing the withdrawn revision and download revision 2. Use the revisions endpoint for a correction you control manually. |
expiring-soon | A downloadable revision with a one-hour window. | Requested, then available. Inspect downloadableUntil, then send a warning or expire it explicitly. |
At most 50 non-expired, non-withdrawn sandbox exports can be active for one lab. Reset when you need a fresh set. Simulator commands have a separate allowance of 60 requests per minute. The sandbox also has its own per-lab API allowance; the shared IP allowance still applies.
These endpoints require a test key with sandbox:manage. Ordinary reads,
downloads, receipts, confirmation, unlock and webhooks use their normal endpoints
and scopes. Idempotency-Key is optional on simulator writes; provide it when
the caller might retry. Its scope is the sandbox, and keys are retained for
30 days. Use a new value for every distinct command.
While files are rendering, another simulator command or a test-mode download,
receipt, confirmation or unlock may return 409 SANDBOX_BUSY. Wait for
PREPARING to finish and retry the same request with its original idempotency
key where applicable. Export reads and the event feed remain available.
curl --fail-with-body -sS -X POST "$API/sandbox/exports" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>" \
-H "Content-Type: application/json" -d '{"scenario":"pages-pdf"}'Returns { "reference": "...", "revision": 1 } while generation is queued.
Release any lab lock first. This withdraws the published revision and queues
revision n+1 with the same export reference.
curl --fail-with-body -sS -X POST "$API/sandbox/exports/$REFERENCE/revisions" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>"Expected events: export.withdrawn, export.requested, then export.available.
curl --fail-with-body -sS -X POST "$API/sandbox/exports/$REFERENCE/withdraw" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>"The revision becomes unavailable and emits export.withdrawn. Your integration
should cancel any production work it has not already committed.
curl --fail-with-body -sS -X PUT "$API/sandbox/exports/$REFERENCE/order" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>" \
-H "Content-Type: application/json" \
-d '{"orderNumber":"TEST-1001","externalOrderId":"test-order-1001","orderedCopies":2}'These fields may also be null. The next export read shows the new current
order. Existing revision snapshots remain frozen. This call emits no partner event.
curl --fail-with-body -sS -X POST "$API/sandbox/exports/$REFERENCE/expiring" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>"Emits export.expiring without changing the global clock.
curl --fail-with-body -sS -X POST "$API/sandbox/exports/$REFERENCE/expire" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>"Closes the download window immediately and queues normal retention processing.
The retention worker deletes the files and emits export.expired. Existing
download URLs must not be treated as permission to produce an expired revision.
curl --fail-with-body -sS -X POST "$API/sandbox/reset" \
-H "Authorization: Bearer $SPREADU_KEY" -H "Idempotency-Key: <unique-command-id>" \
-H "Content-Type: application/json" -d '{}'Returns { "deletedExports": 0 } with the number removed. It removes sandbox
exports, partner events, webhook deliveries and checklist progress, and schedules
their file cleanup. Keys and endpoints remain. The event sequence is not reused;
restart feed reconciliation after reset. Retrying the same reset command returns
its original response rather than deleting new work created afterwards.
Sandbox exports, events, delivery records and files are retained for 30 days. The daily cleanup removes expired sandbox rows; keys and endpoints stay until you remove them.
A receiver must be reachable at a public HTTPS URL on port 443. Localhost, private networks and IP-literal destinations are refused in test mode too. Use a tunnel rather than changing destination validation.
Run a receiver on 127.0.0.1:3005, then choose one tunnel:
# Cloudflare Tunnel: use the generated https://...trycloudflare.com address
cloudflared tunnel --url http://127.0.0.1:3005
# Or ngrok: use its HTTPS forwarding address
ngrok http 3005Your destination is https://<tunnel-host>/spreadu. Keep the receiver and tunnel
running. A temporary tunnel URL can change when restarted; update the endpoint
instead of leaving a dead destination configured.
Use a Standard Webhooks library. The signed
content is webhook-id.webhook-timestamp.raw-body; the library checks both the
signature and timestamp. Read the raw body before JSON parsing, verify it, and
deduplicate by webhook-id. Return 2xx after safely recording the event.
// bun add standardwebhooks
import { Webhook } from "standardwebhooks";
const raw = await request.text();
const secret = process.env.SPREADU_WEBHOOK_SECRET;
if (!secret) throw new Error("Configure the endpoint signing secret.");
const event = new Webhook(secret).verify(
raw,
Object.fromEntries(request.headers),
);
// Persist the verified event under a unique webhook-id before returning 204.// composer require standard-webhooks/standard-webhooks
require 'vendor/autoload.php';
$raw = file_get_contents('php://input');
$headers = array_change_key_case(getallheaders(), CASE_LOWER);
$verifier = new \StandardWebhooks\Webhook(getenv('SPREADU_WEBHOOK_SECRET'));
$event = $verifier->verify($raw, $headers);
// Persist the verified event under a unique webhook-id before returning 204.# python -m pip install standardwebhooks
from standardwebhooks.webhooks import Webhook
import os
raw = request.get_data() # Flask: preserve the raw bytes
headers = {name.lower(): value for name, value in request.headers.items()}
event = Webhook(os.environ["SPREADU_WEBHOOK_SECRET"]).verify(raw, headers)
# Persist the verified event under a unique webhook-id before returning 204.Catch verification failures and return a non-2xx response without processing the body. Never disable the timestamp check to make an old captured request pass. Use Resend to get a fresh signed attempt. During secret rotation, the new and previous secrets both sign for 24 hours; one valid signature is enough.
In the delivery inspector, compare the three webhook headers and raw body with your receiver's input. Check that your reverse proxy preserves them. The response preview is limited to the first 2 KB; use your receiver's logs for larger errors. Signing secrets and API keys are not part of the captured request.
Download the TypeScript example or PHP example. Each includes a local receiver and a full-cycle client. They require a Full access test key and a working HTTPS tunnel. They leave their exports and webhook endpoint available for inspection. Use an endpoint created by the same API key. If you already added the tunnel URL in the portal, remove that endpoint before running the example; an API key cannot manage a portal-created endpoint.
TypeScript uses Bun:
unzip spreadu-typescript-example.zip
cd typescript
bun install
export SPREADU_WEBHOOK_SECRET_FILE="$PWD/.spreadu-webhook-secret"
bun run receiver
# In another terminal in this directory, start the tunnel and then:
export SPREADU_KEY="<your-test-key>"
export SPREADU_WEBHOOK_URL="https://<tunnel-host>/spreadu"
bun run cyclePHP requires PHP 8.2+, cURL, JSON and Composer:
unzip spreadu-php-example.zip
cd php
composer install
export SPREADU_WEBHOOK_SECRET_FILE="$PWD/.spreadu-webhook-secret"
php -S 127.0.0.1:3005 receiver.php
# In another terminal in this directory, start the tunnel and then:
export SPREADU_KEY="<your-test-key>"
export SPREADU_WEBHOOK_URL="https://<tunnel-host>/spreadu"
php full-cycle.phpThe client saves and rotates the endpoint secret in the shared local file; the
receiver reads it for each attempt. Export the same SPREADU_WEBHOOK_SECRET_FILE
in both terminals, or keep their working directories the same. No secret is
printed. Keep the file outside version control and remove it when finished.
The cycle lists exports, follows a cursor, creates and replays a simulator command,
downloads and checks a complete revision, records a receipt twice, confirms and
unlocks an order, requests a correction, downloads revision 2, sees withdrawal in
the feed and waits for a successful webhook delivery. The receivers keep a local
journal and deduplicate events. In your production integration, use a durable
inbox with a unique event ID and your normal processing queue.
The clients retry SANDBOX_BUSY and honor Retry-After on rate limits, within a
two-minute retry budget per call. Other failures include the request ID so you
can inspect them before deciding whether to retry.
Download the generated Bruno collection,
Postman collection
and test-mode Postman environment.
Set apiKey locally to your test key and webhookUrl to your receiver URL.
Never export a collection or environment containing your key.
Requests come from the published OpenAPI document. Successful responses save
reference, revision, after and webhookId where applicable. Start with
getMe, then createSandboxExport, then ordinary export operations. Set a new
idempotencyKey for every new simulator command. Run requests individually;
reset, withdraw and expiry intentionally change the sandbox state.
For offline unit tests, generate a static mock from the OpenAPI document, for example with Prism. A static mock can exercise request and response shapes; use Test mode to prove transitions, retries, event sequencing and signatures.
The portal checklist is calculated from actual sandbox activity. It checks that your integration listed exports and followed a cursor, requested every file in a revision, recorded a receipt, confirmed and unlocked an order, downloaded a correction, accepted a real webhook with 2xx, rotated an endpoint secret and replayed an idempotency key.
When every item is complete, Request live access emails
[email protected] with your lab identity and checklist. Live access remains an
admin decision. After approval, create a live key and switch the key in your
application. Keep the base URL and production handling the same; simulator
endpoints are only for your test harness.
In API settings, use the request log's method, path, status, error code, duration
and x-request-id to find a failed call. The last 50 authenticated calls are kept
per key in both modes. The log stores metadata only. Share the request ID when
asking for help.
| Symptom or code | Fix |
|---|---|
Test mode is unavailable or API_ACCESS_DISABLED | Check that your lab is active and the sandbox rollout is enabled. Live and test access are separate. |
INVALID_API_KEY | Send Authorization: Bearer <complete-key>. Check that the key was not revoked. Never paste the webhook secret here. |
TEST_MODE_REQUIRED | Use a spreadu_lab_test_ key for simulator endpoints. |
INSUFFICIENT_SCOPE or MODULE_NOT_ENABLED | Use a test key with sandbox:manage for simulation and the ordinary export/webhook scopes for those operations. |
EXPORT_NOT_FOUND | Check the reference and selected mode. Test keys cannot see live exports or another lab's exports. |
REVISION_NOT_DOWNLOADABLE | Wait for export.available or use data.downloadableRevision when non-null. A withdrawn or expired revision is not a retry target. |
IDEMPOTENCY_CONFLICT | Reuse a key only for the original operation and body. Give a different command a new key. |
SANDBOX_BUSY, SANDBOX_EXPORT_LOCKED, SANDBOX_STATE_CONFLICT or SANDBOX_EXPORT_LIMIT | For BUSY, wait for preparation and retry the same command. For LOCKED, call DELETE /exports/{reference}/lock with an exports:confirm key. For STATE_CONFLICT, read the current export state before choosing the next action. Reset when the sandbox reaches its export limit. |
No webhook, or DNS_REJECTED, CONNECT_FAILED, HTTP_STATUS | Keep the HTTPS tunnel running, verify its current URL and your receiver's route, return 2xx after recording the event, and inspect or resend the delivery. A local/private destination is not allowed. |
Signature failure or CURSOR_EXPIRED after a long pause/reset | Verify the exact raw body with the correct endpoint secret and a synchronized clock. Resend old webhook captures; reconcile exports and restart the feed if its cursor expired. |
A 429 response includes Retry-After: wait that many seconds. For a retryable
network failure or 5xx, back off and retry the same simulator command with its
original idempotency key. Check the request log before creating replacement work.
Allow analytics to help us improve these docs? We measure page visits and outgoing links. No session recordings. Privacy policy