Skip to content

Segments & freshness

Status-driven system-attribute updates are immediate; purely time-driven lifecycle drift can lag up to 24h. The segment.customer.* webhook events follow membership on a 5-minute sample that runs later under load (see Events from the membership sample).

Segments are created and edited in the Nine Tables app. This API reads them, counts them and serves their members; no route here writes a segment, and none archives one.

A segment’s kind decides what its count and its member pages serve:

  • dynamic — membership IS the rule set, evaluated live, so it moves as customer data does.
  • fixed — a frozen list, which moves only when the list itself is edited. It serves that list whatever its rules say.

The rules are published only on GET /segments/{id}, as rules (see Reading a segment’s rules).

A dynamic segment whose rules read a computed attribute the platform has not finished computing (its definition’s compute_state is computing or failed) is not evaluated: its count and its member pages answer 409 segment-pending, naming those attributes in pending_attributes and carrying Retry-After. A computation starts when a computed attribute is switched on or its rule changes, so wait and retry rather than reading the refusal as an empty segment. A fixed segment never answers it.

A segment’s updated_at moves on every edit to its name, description, rules or archived state, and when a webhook subscription starts or stops covering it, but NOT as its membership changes: a dynamic segment’s members shift with the underlying customer data and write nothing to the segment, so polling updated_at does not track membership.

GET /segments lists the tenant’s non-archived segments, ordered by name and unpaginated (a tenant holds at most 200); include_archived=true adds the archived ones. A listed segment carries no rules: GET /segments/{id} returns the same fields plus description, rules and created_at. Nothing enforces unique names, so two segments can share one; address a segment by its id.

An archived segment is still readable from GET /segments/{id}, but its count and its member pages answer 404 segment-archived. A segment that does not exist answers 404 not-found on all three, so tell the two apart by type.

A key limited to some restaurants does not see every segment, and counts only bookings at its restaurants in a segment’s booking conditions (see Keys limited to restaurants).

rules is a tree exactly two levels deep: a customer is a member when they satisfy every condition of at least one group, OR over groups and AND within one, with nothing below that and no NOT. Membership is a set, so a customer matching three groups is one member. Deleted, anonymised and demo customers are left out before any condition applies, and no condition matches them back in. Inside a group, order carries no meaning, the three kinds of condition mix freely, and one definition_key may appear in several conditions, each narrowing that attribute further.

An attribute condition tests a stored customer value:

  • Only is_not_set matches an unset attribute. Every other operator is evaluated against a stored value, so a customer never given the attribute matches none of them, and is_set means exactly “a value is stored”.
  • Text matching is case-insensitive for eq, neq, in and the contains/not_contains/starts_with/ends_with family. select and multi_select values are canonical keys, compared exactly.
  • The anniversary_* operators compare month and day in the tenant’s time zone, so a birthday rolls over at local midnight, and 02-29 matches in leap years only.
  • The *_days operators count calendar days from the tenant’s today on a date attribute: in_next_days includes today, and in_last_days 7 includes the day seven days back. On a datetime attribute they are rolling windows of N × 24 hours from now.
  • Every day count, in an operator’s value, in days and in a booking window, is a whole number from 1 to 36500, except anniversary_next_days, which takes 1 to 1461: that many days already hold every month and day, 02-29 included.
  • key_in_group matches a customer holding any counter key the named group lists in item_keys, resolved when the rule is compiled rather than stored with it.

A booking condition counts the customer’s bookings that fall in its window and pass every one of its filters. Cancellations and no-shows count unless a status filter leaves them out, so a rule about visits has to say so, and deleted bookings never count. There is no gt or lt count operator (move count by one instead), and lte or eq against 0 is how a rule says “has not booked”.

A tag condition names guest tags by id, and no route on this API resolves an id to its name, so a rule you read shows that a tag condition exists without saying which tags it names. A tag deleted in the Nine Tables app since the rule was saved is dropped before evaluation rather than failing it. Once every id is dropped, the condition is false for has_any and has_all and true for has_none, so the negation is never inverted.

GET /segments/{id}/count counts a fixed segment’s frozen list, and evaluates a dynamic segment live under a time budget. Counts may be up to 60s old:

  • is_capped: true means the true count exceeds 10000, and the count is served as 10000.
  • count: null means only that the evaluation ran out of time: nothing was counted, so retry later. A segment still waiting on a computed attribute answers 409 segment-pending instead (see Dynamic and fixed segments).

GET /segments/{id}/customers pages a segment’s members by customer id ascending, at most 100 rows a page. Customer ids are not uniformly time-ordered, so do not read the page order as “oldest customer first” or sort a timeline by it.

A dynamic segment is evaluated LIVE PER PAGE, so its membership can shift between two page requests: a customer who enters mid-walk after your cursor appears, and one who exits before it is reached does not. A full walk is therefore eventually consistent rather than a point-in-time snapshot, and diffing two walks to reconstruct transitions misses anything that moved during either of them. Page this route to enumerate the members, and track changes with the segment.customer.entered and segment.customer.exited webhooks.

A row carries the member’s id, the key it holds for the system you name in ?source_system= (both halves null where it holds none, and no key at all when you name no system), created_at, when Nine Tables first recorded the guest, and two presence flags, has_email and has_phone. A flag is true when the stored value is neither null nor empty, so you can size an e-mail campaign without reading any contact data. The rest is behind include=:

  • include=contact adds the name, email and phone and marketing consent, and needs contacts:read;
  • include=attributes adds the attribute value set, needs attributes:read, and lowers the page size to 25 rows; a limit above that is clamped to it rather than refused.

A field you did not ask for is ABSENT rather than null, so test for presence.

The checks run in a fixed order, which decides the error a request that is wrong in two ways sees. limit, the shape of sort (<key> or -<key>), the count of filter parameters and each one’s length are checked first, before the {id} and before the segment is looked up. cursor, include, the scope an include extra, a filter or a sort needs (attributes:read for the last two), a filter’s key, operator and value and a sort’s key are checked only AFTER the segment resolves, so on a segment that does not exist or is archived those answer 404: fix the {id} first. That order is what stops a key holding segments:read but not the extra’s scope from using the 403 to learn which segments exist.