Segments
A segment is a saved set of rules over the contacts of your account. Its members are the contacts that match the rules. A rule can read:- A field of the contact:
email,first_name,last_name, one of your own fields, orcreated_at, the time the contact was created. - A list membership.
- The campaigns that the contact received, opened or clicked: one campaign, or any campaign since a time.
- The number of campaigns that the contact received, opened or clicked since a time.
- The month and day of one of your date fields, for birthdays and anniversaries.
30 days ago are read again on a schedule.
Segment names do not have to be unique in an account. An account can have at most 100 segments.
A list, a campaign or a contact field that a segment uses in a rule cannot be deleted while the segment uses it. Delete List and Delete Campaign answer 409 with a message that names the segments, such as Used by segments: A, B. Change those segments first.
Definitions
definition holds the rules of a segment:
schema_versionis1.matchisallwhen a contact must match all of the conditions, oranywhen one is enough.conditionsholds at least one item. An item is a condition or a group. A group has its ownmatchandconditions, and holds conditions only, so groups nest one level deep.- A condition has a
field, an operator inopand, for most operators, avalue. For an operator that takes no value, such asis_empty, leavevalueout or sendnull. - A definition has at most 50 conditions in all. At most 5 of them are
campaign,any_campaignorcampaign_countconditions. - An unknown key is refused. A refused definition answers
400, and the message names each problem by its path, such asconditions[3].value.
Conditions
Your own fields are
attributes.<key>, with the key of a contact field that you defined in the dashboard. A condition on a key that the account does not have is refused.
Rules of the conditions:
- Your date, number, timestamp and boolean fields also take
is_nullandis_not_null.email,first_name,last_name,created_atand your text fields do not. - A negated operator, such as
not_equalornot_contains, also matches a contact that has no value for the field. listwithinmeans aconfirmedmembership of the list.campaignwithreceivedmeans that the campaign was delivered to the contact.not_openedandnot_clickedmatch only contacts who received the campaign.any_campaignwithreceived,openedorclickedmatches a contact with at least one such event since the time.not_openedandnot_clickedmatch a contact who received a campaign since the time and opened, or clicked, none since then.- Opens and clicks by bots do not count.
Campaign Counts
Acampaign_count condition takes an object as its value, such as {"count": 3, "since": "90 days ago"}. It counts the campaigns sent since since that the contact received, opened or clicked.
countis a whole number from 1 to 1,000, or from 2 forreceived_fewer_than.sinceisM days ago,M weeks ago,M months agoorM years ago, with M up to 365 days, 52 weeks, 12 months or 1 year. The window starts at the beginning of its day in the segment’s time zone.- A campaign counts from the time it started sending, whenever the contact received, opened or clicked it. Several opens or clicks of one campaign count once.
received_fewer_than,opened_fewer_thanandclicked_fewer_thanmatch only a contact who received at least one campaign sent since then.- A missing or unknown property of the object is refused.
Birthdays and Anniversaries
Two operators on your date fields read only the month and day, so the year does not matter:month_istakes a month from1(January) to12(December).anniversary_withintakes a number of days N from0to365. It matches when the month and day fall on today or on one of the next N days in the segment’s time zone.0is today only.
YYYY-MM-DD date, as the API and imports store it. Any other value never matches. The members of an anniversary_within segment move to the new day shortly after midnight in its time zone, usually within about half an hour.
Time Zone
timezone is an IANA time zone, such as Europe/Berlin. Relative times, such as today or 30 days ago, and days are read in this zone. Without one, the segment uses UTC. An unknown time zone is refused with 400.
States
- A new segment is
building. An update that changesdefinitionortimezonebuilds the members again, and the segment isbuildinguntil that ends. An update of onlynameordescriptionkeeps the members and the state. - While a segment is
building, List Segment Contacts and List a Contact’s Segments may still answer by the previous rules. - Any update of a
failedsegment,{}included, builds it again. - A campaign that uses a segment, included or excluded, cannot be sent while the segment is
buildingorfailed. Send Campaign refuses it with400, and the message names the segment. last_evaluated_atis the time the members were last checked against the whole account. It isnulluntil the first build ends.
Members and Reachable Contacts
The members of a segment are the contacts that match its rules, whatever their consent.member_count and List Segment Contacts include all of them.
A campaign to a segment reaches only the members who can get marketing email. A member is reachable when:
- The contact is
enabled. - The contact is not unsubscribed account-wide.
- Email validation did not find the contact invalid.
- The contact is
confirmedon at least one list, or is on no list at all.
unsubscribed, complained or unconfirmed is not reached. A contact on no list can be reached, which a campaign to lists cannot do.
Get Segment returns marketable_count, the members that a campaign to this segment alone would reach. It is null while the segment is not ready, and when the members cannot be counted within 10 seconds. The campaign checks its contacts again when it starts.
Campaigns and Segments
A campaign sends to the segments insegment_ids, and leaves out the members of the segments in exclude_segment_ids. See Audience for the rules of a campaign’s lists and segments.
A segment send has no list to leave. A contact who unsubscribes from a segment send, or reports it as spam, is unsubscribed account-wide and gets no more marketing email from your account. The contact’s unsubscribed becomes true. See Contacts, lists and segments.
A segment that a campaign still needs, as an included or an excluded segment, cannot be deleted. Campaigns in draft, validating, scheduled, sending, paused or waiting_for_review block the delete.
Preview a Definition
Preview Segment tries a definition without saving it. It returnscount, the contacts that the definition matches now, whatever their consent, and up to 10 of them. It changes nothing.
Pagination
List Segments and List a Contact’s Segments return segments newest first. List Segment Contacts returns members by contact ID, lowest first. Each page givespagination.has_more, pagination.next_cursor and pagination.previous_cursor. Send next_cursor as after for the next page, or previous_cursor as before for the previous page. You cannot send after and before together. limit is 1 to 100, and the default is 100.
Conflicts
A segment write that meets another change answers409 and changes nothing:
Do not use the
message to tell the cases apart.
Scopes
Preview Segment, List Segment Contacts and List a Contact’s Segments read contacts, so they also need
contacts:read. See Permission scopes.
Idempotency
Create Segment accepts anIdempotency-Key header. A 2xx answer is stored for 24 hours, so a retry with the same key creates no second segment. Unlike most operations, a 4xx answer is not stored: it releases the key, so a retry with the same key runs again, for example after you delete a segment. A request with the same key that is still in progress answers 409 with Idempotent-Replayed: false and a Retry-After header; retry with the same key after that delay. See Idempotency.

