Loading...

Stock levels

A stock field is a count on a record that can never be oversold: however many buyers take at once, available never goes below zero.

  • Switched on per service. Where it is off, every stock route answers 404 “not available”.
  • One count, read by search, filters and verify_offer: they show available.
  • Every change writes one movement saying who, why and which API key. Not enough answers done: false and changes nothing; it is never an error.
Set up a stock field
  • Mark a single-valued Number facet: PUT /facet/{account}/{list}/{facet}/stock (MCP facet_set_stock, needs facet:rename). stock: false unmarks it.
  • Marking makes the facet volatile. Deltas and the volatile patch then refuse it, so only the stock routes change the count.
  • A stock field cannot be renamed (counts are kept under its name) or retyped away from Number. Unmark it first.
SettingDefaultWhat it does
low_atnoneAvailable at or below this sends stock.low. With none, only sold out alerts.
default_hold_seconds600How long a hold lasts when the caller does not say.
max_hold_seconds86400The longest hold a caller may ask for (at most 24 hours).
confirm_after_timetrueA hold past its time not yet given up can still be confirmed, so a late payment is honoured. False: it is given up instead.
keep_history_daysfor goodMovements older than this are removed daily (at least 30).
in_stock_fieldnoneA Boolean facet set true while available is above zero and false at zero, so “only in stock” filters in search.
The counts
  • available: what can be taken or held now. held: set aside in active holds. on_hand = available + held.
  • A record with no count yet has zero. Start one with add or correct.
  • Search shows the count within moments of a change; levels is the exact read.
Routes

Paths start /stock/{account}/{list}. {id} is the record's id (the id of a search hit); {field} is the stock field.

RouteMCP toolPermissionWhat it does
POST …/{id}/{field}/takestock_takestock:editTake quantity outright.
POST …/{id}/{field}/holdstock_holdstock:editSet quantity aside for held_for for seconds. Answers hold_id, expires_at.
POST …/hold/{hold_id}/confirmstock_confirm_holdstock:editTurn a hold into a take. Twice is fine. 409 if released or expired: ask again.
POST …/hold/{hold_id}/releasestock_release_holdstock:editGive a hold back. Twice is fine. 409 if confirmed.
POST …/{id}/{field}/addstock_addstock:editAdd quantity; kind is received or put_back.
POST …/{id}/{field}/correctstock_correctstock:editSet available after a recount; why required. cancel_holds: true gives every hold up first.
POST …/{field}/levelsstock_levelsstock:readCounts of up to 100 ids, in the order asked.
GET …/{id}/{field}/movementsstock_movementsstock:readHistory, newest first. limit 1–200 (50), then next.
  • Every change needs who (a person, an order, a system); why is optional except on correct.
  • request_key (take, hold, add, correct) makes a retry safe: the same key on the same record and field is applied once and a repeat answers the first result.
  • The movement records the API key’s name. The API sets it; a request body cannot.
  • Both permissions can be scoped to one list.
Webhooks

Sent only when a mark is crossed, so a count sitting at zero does not alert on every failed take.

EventWhen
stock.lowAvailable falls to or below low_at.
stock.sold-outAvailable reaches zero. Sent instead of stock.low when one change does both.
stock.back-in-stockAvailable leaves zero.
stock.hold-expiredA hold runs out and its stock comes back. Not sent for a release.
  • The first three carry account_name, list_name, id, field, available, held, on_hand, low_at, as_of, movement_id.
  • stock.hold-expired carries account_name, list_name, id, field, hold_id, quantity, available, held, as_of, movement_id.
  • Subscribe like any other event: webhooks.
Limits
  • Quantity 1 to 1,000,000,000 per change; a count never passes 1,000,000,000.
  • Hold 30 seconds to the field’s max_hold_seconds. Holds past their time are given up within about a minute.
  • Rate limited with search (the plan’s per-minute allowance), not the ingest tier.
Top