Stores: inventory sync
Keeping a shop’s stock in step by SKU or barcode, holds, questions and the storefront.
Access
Store routes take the store’s id in the path (/stores/{storeId}/…) and a member of that store as the caller. An inventory system uses a store key: it reaches its own store only (another store’s id, or a hold, question or listing of another store, is a 404), and only with the store scopes it was given. The “Store inventory sync” preset is what a point of sale needs.
A store key acts as the manager who made it: what only owners may do (invite people, change roles) needs a key an owner made, and the key stops working if its maker leaves the store or becomes staff.
Keeping inventory in step
Upsert listings by SKU or barcode takes up to 500 rows and answers a result for each, in order:
- The key is your
sku, or thebarcodewhen there’s no SKU. A key the store already lists updates that listing with the fields you send (unchangedwhen nothing differs); a new key creates one. Copies of one book in different grades need their own SKUs. - A new listing needs its book: an
issueId, or a barcode we match the way the scanner does (Barcodes). When one book isn’t clearly it, the row isunmatched, with candidates: send the right one’sissueIdnext time. - Rows stand alone: one that fails says why (
error.code) and the others are saved. Send anIdempotency-Key, so a retry answers the first result instead of running again.
Adjust stock applies sales and deliveries as deltas (or sets a count), by listing id, SKU or barcode; stock never goes below 0, and a listing at 0 is sold out until stock returns. List the store’s inventory with sort=updatedAt and filter[updatedSince] reads back what changed since your last run, holds included (an accepted hold takes its copies out of the stock). Match barcodes to the catalog checks a delivery first, without saving anything.
import { createCollectorClient } from '@collector/sdk';
// A store key with store:inventory:read and store:inventory:write (the "Store inventory sync" preset).
const collector = createCollectorClient({ token: process.env.COLLECTOR_STORE_KEY });
const storeId = '00000000-0000-4000-8000-000000000000';
// 1. Push the register's stock: keyed by your SKU, or by the barcode when there's none. A key the
// store already lists is updated; a new one is created once its barcode matches one book.
const { created, updated, unchanged, results } = await collector.upsertInventory({
path: { storeId },
body: {
items: [
{ sku: 'XM1-CGC94', barcode: '75960604391000111', price: { amountCents: 8500, currency: 'USD' }, quantity: 1 },
{ barcode: '75960620100600311', price: { amountCents: 400, currency: 'USD' }, quantity: 3 },
],
},
// The same key on a retry answers the first result: nothing is written twice.
idempotencyKey: crypto.randomUUID(),
});
console.log(`${created} created, ${updated} updated, ${unchanged} unchanged`);
// 2. Rows whose barcode didn't clearly match one book come back with candidates: pick one and
// send its issueId (with the same SKU or barcode) next time.
for (const row of results.filter((r) => r.status === 'unmatched')) {
for (const c of row.match?.candidates ?? []) console.log(row.index, c.issueId, c.seriesTitle, c.number, c.score);
}
// 3. A sale at the counter: take one off the stock (it's sold out at 0).
await collector.adjustInventoryStock({
path: { storeId },
body: { adjustments: [{ sku: 'XM1-CGC94', delta: -1 }] },
idempotencyKey: crypto.randomUUID(),
});
// 4. Read back what changed since the last run (holds and sales change stock too), page by page.
for await (const page of collector.pages('listInventoryItems', {
path: { storeId },
query: { 'filter[updatedSince]': '2026-10-12T00:00:00Z', sort: 'updatedAt', limit: 200 },
})) {
for (const item of page.data) console.log(item.sku ?? item.barcode, item.quantity, item.status);
}Importing stock from a CSV
Two calls: a preview, which saves nothing, and a commit of the rows you’ve checked.
- Preview an inventory CSV: send the file’s text as
csv. Headers are recognised loosely (“Series” or “Title”, “Issue #” or “No.”, “Price”, “Qty”…); a title, an issue number and a price column are required. Each row comes back with its parsed fields, its problems, and amatch:matched,ambiguous,not_foundorinvalid, with candidates. - Import inventory rows: send the rows to list, each with the catalog
issueId(andeditionIdwhen known) you chose. It’s idempotent, so a retry can’t list a row twice.
import { createCollectorClient } from '@collector/sdk';
const collector = createCollectorClient({ token: process.env.COLLECTOR_TOKEN });
const storeId = '00000000-0000-4000-8000-000000000000';
// 1. Preview: the API reads the CSV and matches each row to the catalog. Nothing is saved.
const csv = ['title,issue,price,qty', 'Saga,1,24.99,2', 'The Amazing Spider-Man,300,450.00,1'].join('\n');
const preview = await collector.previewInventoryImport({ path: { storeId }, body: { csv } });
// 2. Keep the rows that matched one book; check the rest by hand.
const rows = preview.rows.flatMap((row) => {
const { match } = row;
const pick = match.candidates.find((c) => c.key === match.chosenKey) ?? match.candidates[0];
if (match.status !== 'matched' || !pick?.issueId || row.errors.length) {
console.warn(`line ${row.line}: ${match.status}`, row.errors.join(' '));
return [];
}
return [
{
line: row.line,
issueId: pick.issueId,
editionId: match.editionId ?? pick.editionId,
fields: row.fields,
},
];
});
// 3. Commit them. The client sends an Idempotency-Key, so a retry can't list them twice.
const { created, failed } = await collector.commitInventoryImport({ path: { storeId }, body: { rows } });
console.log(`${created} listed, ${failed.length} failed`);One listing at a time
- Find a book to list, then List a book with its price in cents, quantity, condition or grade, and status.
- List the store’s inventory (the dashboard’s model) filters by status and text, and pages by
limitandoffset; Get an inventory item reads one as the inventory resource. - Update a listing for price and stock changes; Set many listings’ status to hide or restore many at once.
Holds and questions
Collectors ask a store to hold a book, or ask a question about one. The store reads them in List the store’s holds and List questions to the store (a page at a time, with cursor), and answers under its own path:
- Accept a hold request sets the copies aside (out of the stock) for the store’s hold days; Decline a hold request closes it, with a reason. A request nobody answers expires after 48 hours, an accepted hold at its
expires_at, and either way the copies go back on sale. - Record a hold’s sale closes it at the final price and records the seller fee.
- Answer a question replies in its thread.
To hear about new holds, questions and sales as they happen, give the store a webhook (Webhooks): hold.requested, question.asked, listing.sold and the rest, rather than polling the lists.
Storefront, team and billing
- Get the storefront and Update the storefront: the profile, contact details, address, opening hours and policies (holds, shipping). Send only what changes; owners and admins.
- List the store’s team and Invite someone to the team (owners).
- Read-only billing: Get the store’s billing (the fee rate and payment method), List the store’s seller fees and List the store’s invoices. Owners and admins.