Segments
Group contacts explicitly or select them with dynamic rules, then count the recipients before a broadcast.
A segment selects contacts within one project. Use a static segment for a list you manage and a dynamic segment for a condition that should be evaluated against current data. Both can be the recipient list of a broadcast.
Static lists
Create a list with POST /segments:
{"name":"Product updates"}Add a contact with POST /contacts/{id_or_email}/segments/{segment_id} and remove it with
DELETE on the same path. Adding a member twice changes nothing further. You can also
pass segments: [{"id":"<segment_id>"}] when creating a contact.
The deprecated /audiences routes refer to these same static segments. Deleting a
segment removes its memberships, not the contacts. A static segment may require
double opt-in.
Dynamic rules
Supplying rules on create makes the segment dynamic. For example, after declaring the
plan string property:
{
"name":"Pro contacts who clicked",
"rules":{
"all":[
{"property":"plan","op":"eq","value":"pro"},
{"activity":"clicked","within_days":30}
]
}
}Combine conditions with all, any and not. Conditions can select a built-in field
(email, names, unsubscribed, language, timezone, created_at), a declared property,
a topic's effective subscription or activity. Activity kinds are sent, delivered,
opened, clicked, bounced and unsubscribed; within_days is required, with optional
min and broadcast_id. Opens and clicks count human hits only.
- Every type supports
eq,neq,in,not_in,existsandnot_exists. - Numbers and dates also support
lt,lte,gtandgte. - Strings also support
contains,not_contains,starts_withandends_with, case-insensitively. String equality is case-sensitive except for email addresses.
A missing property takes its fallback, if declared, except for exists and not_exists,
which ask whether the contact has its own value. Without a fallback, a missing value
matches negated operators such as neq, but no positive operator.
PATCH /segments/{id} changes a dynamic rule. You cannot change a static segment into a
dynamic one or add members to a dynamic segment by hand. Dynamic segments cannot require
double opt-in. A property or topic used by a rule cannot be deleted.
The sunset preset creates a dynamic segment of contacts without a human open or click
in a chosen number of days: {"name":"Inactive","preset":"sunset","days":90}.
It selects people; it does not unsubscribe them.
Count and inspect
GET /segments/{id}/count returns {"object":"segment_count","id":"…","count":42}.
GET /segments/{id}/contacts lists the contacts, with limit, after and before.
A dynamic segment is evaluated when counted, listed or snapshotted for a broadcast.
If evaluation times out, the answer is 503 service_unavailable with Retry-After,
never a partial count.
Reading segment definitions and counts needs read. Changing them or listing their
contacts needs audience; an API key needs full access. A broadcast freezes its own
snapshot when sending starts, so later changes to a rule do not add recipients mid-send.