Skip to content

Segments & topics

The segment filter format (profile, device, activity and action rules) and segment routes, topics, subscriber import/export and bulk labels.

Segments

/api/v1/segments — saved filters you can send to (segmentId), leave out of a send (excludeSegmentId), or attach to an RSS feed or a recurring schedule. A segment's filters, and the inline filters / excludeFilters of a send, use one format:

JSON
{ "match": "all",                  // "all" = every rule must match (default), "any" = at least one
  "rules": [
    { "field": "country",  "op": "in", "value": ["IN", "US"] },
    { "field": "tag:plan", "op": "eq", "value": "pro" },
    { "field": "tag:vip",  "op": "exists" }
  ] }
PartValues
fieldProfile: country (the 2-letter upper-case code from the visitor's IP), language, url (the subscriber's last page), external_id (or externalId), or tag:KEY for one of your tags. Device & activity: device, subscribed_days, last_seen_days, last_clicked_days. Actions: event:NAME. See behaviour rules below. An unknown field matches nobody (the rule fails closed, so a typo can't turn a targeted send into a send to everyone).
opeq (default; for the profile fields also used for an unknown op), neq, contains (case-insensitive), in (value is a list), exists, not_exists (no value needed). For a tag, neq also matches subscribers without that tag, and gt, gte, lt, lte compare the tag's value as a number.
valueCompared as text, exactly: eq, neq and in are case-sensitive (only contains ignores case), so write country codes in upper case, e.g. "IN". For country, language, url and external_id, neq doesn't match subscribers who have no value.

Behaviour rules

FieldOpsValueMatches
deviceeq, neq, inios, android, mobile (other phones), desktop, otherEach browser on its own: someone with an iPhone and a laptop is in "device is ios" with the iPhone only.
subscribed_dayseq, neq, gt, gte, lt, lteWhole days, 0–3650Days since that browser allowed notifications.
last_seen_daysthe sameWhole days, 0–3650Days since that browser last opened your site.
last_clicked_daysthe same, plus exists, not_existsWhole days, 0–3650Days since the person last clicked one of your notifications. Someone who never clicked has no value: only not_exists matches them (so "more than 30 days ago" leaves them out).
event:NAMEwithin_days, not_within_days, exists, not_existsWhole days, 0–3650 (none for exists / not_exists)An action your site reports with RelayBell.track() or POST /api/v1/events, by its exact (case-sensitive) name: did it at least once in the last N days, didn't (including never), ever, never.
tag:KEYgt, gte, lt, lteA number, such as 5 or 19.99The tag's value as a number. A value that isn't a number ("gold") never matches.

| smart_group | eq, neq | repeat_buyer, big_spender, ready_to_buy, going_quiet | Groups relaybell works out every hour. See automatic segments. | | intent_score | eq, neq, gt, gte, lt, lte | A number, 0–100 | How close the person looks to buying. | | orders, total_spent | the same | A number | Orders seen for the person and what they spent, after refunds. |

Days are whole days: 0 for the first 24 hours, 1 for the next 24, and so on, so "gt", 7 means 8 days or more. gt / gte / lt / lte read "more than", "at least", "less than", "at most". Clicks and actions count only while they are in your activity history (90 days unless you changed it in Settings). Counts stay per browser: a person-level rule (last_clicked_days, event:) includes all of that person's browsers.

JSON
// Did "purchase" in the last 30 days
{ "match": "all", "rules": [{ "field": "event:purchase", "op": "within_days", "value": 30 }] }

// Subscribed more than 7 days ago and never clicked a notification
{ "match": "all", "rules": [
    { "field": "subscribed_days",   "op": "gt", "value": 7 },
    { "field": "last_clicked_days", "op": "not_exists" } ] }

// Put something in the cart this week but didn't buy, on a phone
{ "match": "all", "rules": [
    { "field": "event:add_to_cart", "op": "within_days",     "value": 7 },
    { "field": "event:purchase",    "op": "not_within_days", "value": 7 },
    { "field": "device",            "op": "in",              "value": ["ios", "android", "mobile"] } ] }

// Regular readers: 10 or more visits (a tag your site keeps), seen this week
{ "match": "all", "rules": [
    { "field": "tag:visits",     "op": "gte", "value": 10 },
    { "field": "last_seen_days", "op": "lt",  "value": 7 } ] }

A malformed rule (days that aren't a whole number from 0 to 3650, an unknown device, an action without a name, a number op on a field without numbers, or a rule that isn't an object) is refused with 400 { "error": "invalid_filters", "message": "Rule 2: …" } by the segment routes, /segments/preview and the subscriber list.

RequestWhat it does
GET /api/v1/segments{ segments: [{ id, name, filters, created_at }] }, newest first.
POST /api/v1/segmentsBody { name, filters } → 201 { segment }. 400 name_required without a name. A segment needs at least one complete rule (a field — a tag: field with its key, an event: field with its name — and a value, unless the op is exists / not_exists): otherwise 400 segment_needs_a_rule, because a segment with no rules would include every subscriber. A malformed rule: 400 invalid_filters.
PUT /api/v1/segments/:idChanges name and/or filters (the same rule check) → { segment }. 400 nothing_to_update when neither is sent; 404 not_found for another website's id.
DELETE /api/v1/segments/:id{ ok: true }. While an enabled RSS feed, an enabled recurring schedule, or a scheduled or queued send uses it (to include or to exclude), it answers 409 { "error": "segment_in_use", "feeds", "schedules", "pending" } with how many of each.
POST /api/v1/segments/previewBody { filters, topicId? } → { count }: how many subscribed browsers match right now (a person on two devices counts twice), optionally within a topic (id or slug). 400 invalid_filters for a malformed rule.
GET /api/v1/audience/segmentsYour saved segments with their size: { segments: [{ id, name, filters, created_at, count, lastUsedAt, sends, usedBy: { feeds, schedules } }] }. count is the same number /segments/preview gives. Needs subscribers:read.

Creating, changing and deleting a segment is recorded in the account's activity log (segment.created, segment.updated, segment.deleted). Writes need segments:write. A send that names a segment which isn't in this website is refused (400 segment_not_found), and one whose segment is deleted before it goes out ends failed with segment_missing — a missing segment never means "everyone".

Automatic segments

relaybell adds these to your segments by itself and refreshes them every hour. Send to them like any other segment; they can't be edited or deleted (409 segment_automatic). Each appears once your website has the data for it.

Segmentsmart_groupWho's in it
Bought twice or morerepeat_buyerAt least two orders, not counting fully refunded ones.
Big spendersbig_spenderThe top 10% of buyers by total spent, once you have 10 buyers.
Ready to buyready_to_buyA buying intent of 40 or more.
About to go quietgoing_quietActive on at least 3 different days in the last 90, but with no action, click or visit for 21 to 60 days.

Orders come from purchase, order.completed and checkout.completed events linked to a subscriber, once per orderNumber (or orderId). value (or revenue) is the amount, added up as reported. order.refunded with the same order takes off its amount, or the whole order if it has none, and an order.status_changed to cancelled, refunded or failed removes it. Shopify doesn't report refunds or cancellations to relaybell yet, so Shopify orders count in full. relaybell keeps a separate order history for three years, or for the retention period you've set if it isn't the default 90 days, so a purchase still counts after your activity history clears.

Buying intent is 0–100, from the last 14 days: checkout.started 60, cart.updated 30, waitlist.join 15, product.viewed 8 (24 at most), a click on a notification 5 (10 at most). Each is worth half as much every 4 days, and only what came after the person's latest order counts.

Topics

/api/v1/topics — preference-center categories. GET lists { id, name, slug, created_at, subscribers }; POST { name, slug? } creates one (the slug is made from the name when left out; posting an existing slug renames that topic); PUT /:id { name } renames it (the slug never changes, since subscribers opt in by slug); DELETE /:id. Writes need settings:write. Subscribers opt in via RelayBell.setTopics(["slug"]) / showPreferences(); target a send with topicId (id or slug).

Subscribers

  • GET /api/v1/subscribers/export — CSV of subscribers. GET /api/v1/subscribers/recent?limit=25 — the newest ones (up to 100).
  • POST /api/v1/subscribers/import — body { subscribers: [{ externalId, tags: { … }, topics: ["slug"] }] } (up to 10,000 rows) creates or enriches subscribers by external id → { ok, processed } (400 no_subscribers for an empty list). Push subscriptions themselves can't be imported: each browser must opt in on your site.
  • GET /api/v1/subscribers/:externalId/profile — one person (by external id or relaybell id): { subscriber, tags, endpoints, topics, sends, events, stats }, with their last 50 deliveries/clicks and events; /data and DELETE are under Compliance.
  • GET /api/v1/audience/subscribers — the dashboard's paged, filterable list (filters takes the segment format; there a per-browser rule such as device matches a person with at least one such browser); GET /api/v1/audience/subscribers/facets — the values in use, including events, the action names your site reported lately; POST /api/v1/audience/subscribers/bulk-tag { ids, set: { key: value }, remove: [key] } (at most 20 labels at a time; rb_ keys are reserved) and /bulk-delete { ids } → { ok, deleted }.