Number ranges

How orders, delivery notes and returns get their numbers on revenexx — the three seeded ranges, the shape a merchant gives them, and the settings that point at them.

Three things in the orders app carry a number a human reads: the order, the delivery note, and the return. Each is drawn from a counter the merchant shapes.

Base path: https://api.revenexx.com/v1/orders/number-ranges.

The three seeded ranges

Request
curl -X POST https://api.revenexx.com/v1/orders/number-ranges/defaults \
  -H "X-Revenexx-Tenant: <TENANT_SLUG>" \
  -H "X-Revenexx-Api-Key: rvxk_..." \
  -H "Content-Type: application/json" \
  -d '{}'
CodeNumbersSeeded as
orderOrdersORD- + six digits, step 1
deliveryDelivery notes, drawn by POST /v1/orders/{id}/shipDEL- + six digits, step 1
returnReturns, drawn by POST /v1/orders/{id}/returnRET- + six digits, step 1

The app runs this on install, so a fresh tenant needs nothing. Call it by hand after a range was deleted, or to see what a tenant has.

Idempotent: a code that already exists comes back under existing and is left exactly as it is, counter included, so a merchant who changed the prefix keeps their change. It answers 200, never 201 — it is a reconcile, not a create — and it never repairs or renames a range that is already there.

The shape of a number

text
{prefix}{counter padded to `padding`}{suffix}
FieldMeaning
codeWhich counter this is. Unique per tenant, and the value the settings point at.
prefixLiteral text in front. ORD- turns counter 123 into ORD-000123. Empty by default.
suffixLiteral text after — a market or year marker. Empty by default, which is what most merchants use.
paddingHow wide the counter is written, zero-padded. 6 makes 123 into 000123; 0 writes the bare number. Widening it later does not renumber what was already drawn.
stepHow far the counter moves per draw. 1 is consecutive; a larger step is what a merchant chooses who does not want their order volume readable off an invoice.
counterThe last number drawn — state, not configuration.
position_stepThe gap between the position numbers of a new order: 10 numbers the lines 10, 20, 30, leaving room to slot one in later. Read from the order range only.
channel_idA label. It does not select the range.
metadataFree-form. The app stores it and reads nothing out of it.

counter is state

The next draw is counter + step, and it writes the new value back.

Moving counter forward skips numbers. Moving it back re-issues them, and the unique index on the order number then answers 409. Setting it is a repair, not a configuration.

Because a draw writes the counter, updated_at on a range changes on every single order.

channel_id does not select the range

A draw finds the range by code alone, and the unique index on (tenant, code) means one code is one range per tenant. So an order on another channel draws from the same range this one names. channel_id is a label on the row, nothing more.

Adding a range

Request
curl -X POST https://api.revenexx.com/v1/orders/number-ranges \
  -H "X-Revenexx-Tenant: <TENANT_SLUG>" \
  -H "X-Revenexx-Api-Key: rvxk_..." \
  -H "Content-Type: application/json" \
  -d '{"code":"order_at","prefix":"AT-","padding":6,"step":1}'

A code that is taken answers 409 rather than creating a second counter under the same name. Creating a range renumbers nothing that already exists.

Pointing a setting at it

A new range is only used once a setting names it:

SettingDrawn by
order_number_range_codePOST /v1/orders/place
delivery_number_range_codePOST /v1/orders/{id}/ship
return_number_range_codePOST /v1/orders/{id}/return
A setting naming a code no range carries makes placing an order answer 422. Create the range first, then point the setting at it.

Settings resolve per market, so a per-market number range is a per-market setting pointing at a second range — not a channel_id on the range. See Settings.

Where to go next

  • Orders — where the order and delivery numbers are drawn.
  • Returns — where the return number is drawn.
  • Settings — the market → tenant → default precedence the range codes resolve through.
Was this page helpful?