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 showavailable. - Every change writes one movement saying who, why and which API key. Not enough answers
done: falseand changes nothing; it is never an error.
Set up a stock field
- Mark a single-valued Number facet:
PUT /facet/{account}/{list}/{facet}/stock(MCPfacet_set_stock, needsfacet:rename).stock: falseunmarks 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.
| Setting | Default | What it does |
|---|---|---|
low_at | none | Available at or below this sends stock.low. With none, only sold out alerts. |
default_hold_seconds | 600 | How long a hold lasts when the caller does not say. |
max_hold_seconds | 86400 | The longest hold a caller may ask for (at most 24 hours). |
confirm_after_time | true | A 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_days | for good | Movements older than this are removed daily (at least 30). |
in_stock_field | none | A 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
addorcorrect. - Search shows the count within moments of a change;
levelsis 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.
| Route | MCP tool | Permission | What it does |
|---|---|---|---|
POST …/{id}/{field}/take | stock_take | stock:edit | Take quantity outright. |
POST …/{id}/{field}/hold | stock_hold | stock:edit | Set quantity aside for held_for for seconds. Answers hold_id, expires_at. |
POST …/hold/{hold_id}/confirm | stock_confirm_hold | stock:edit | Turn a hold into a take. Twice is fine. 409 if released or expired: ask again. |
POST …/hold/{hold_id}/release | stock_release_hold | stock:edit | Give a hold back. Twice is fine. 409 if confirmed. |
POST …/{id}/{field}/add | stock_add | stock:edit | Add quantity; kind is received or put_back. |
POST …/{id}/{field}/correct | stock_correct | stock:edit | Set available after a recount; why required. cancel_holds: true gives every hold up first. |
POST …/{field}/levels | stock_levels | stock:read | Counts of up to 100 ids, in the order asked. |
GET …/{id}/{field}/movements | stock_movements | stock:read | History, newest first. limit 1–200 (50), then next. |
- Every change needs
who(a person, an order, a system);whyis optional except oncorrect. 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.
| Event | When |
|---|---|
stock.low | Available falls to or below low_at. |
stock.sold-out | Available reaches zero. Sent instead of stock.low when one change does both. |
stock.back-in-stock | Available leaves zero. |
stock.hold-expired | A 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-expiredcarriesaccount_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.