Segments
A segment picks contacts by rules: make one, count who it matches, and change its rules. This page is generated from the OpenAPI document of release main-6976024, the one the API serves, so it lists only what the API has.
How to authenticate, where errors are explained, and the other resources are in the API reference.
The account's segments
GET /v1/segments
A page of segments, oldest first, without their rules. Archived ones only with state=all.
Its API key needs segments:read.
Parameters
| Parameter | What it is |
|---|---|
cursor | text, in the query. The previous page’s next_cursor. |
limit | a whole number from 1 to 100, in the query. |
state | one of active or all, in the query. all includes the archived. |
Answers
- 200: A page of segments
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 422:
- Validation failed (
validation_failed)
- Validation failed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
data (required) | a list, each an object. |
data[].id (required) | text. |
data[].name (required) | text. |
data[].applied_version (required) | a whole number. |
data[].revision (required) | a whole number. |
data[].has_draft (required) | true or false. |
data[].archived_at (required) | a date and time (RFC 3339), or null. |
data[].created_at (required) | a date and time (RFC 3339). |
data[].updated_at (required) | a date and time (RFC 3339). |
next_cursor (required) | text, or null. Null on the last page. |
Make a segment
POST /v1/segments
Stores the rules as the segment's applied rules, version 1. The rules are refused as 422 segment_invalid, with errors[0].pointer at the first rule refused and errors[0].code why, never the value: a shape the tree doesn’t take, a list, tag, or field the account doesn’t have, an operator the field’s type doesn’t take, a bound passed, or an engagement rule where engagement isn’t recorded yet. An account holds at most 200 segments, archived ones included. A segment that isn't archived with this name, these rules, and no draft already answers 200, so a retry is safe, to a caller that may read segments (a key needs segments:read for it); one with this name in any case and anything else is 409 segment_name_taken.
Its API key needs segments:write.
Request body
A application/json body.
| Field | What it is |
|---|---|
name (required) | text, up to 100 characters. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
Answers
- 200: The account already had it, as asked
- 201: Made
- 400:
- Malformed request (
malformed_request)
- Malformed request (
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 409:
- Segment name already in use (
segment_name_taken) - Too many segments (
segment_limit_reached)
- Segment name already in use (
- 413:
- Request body too large (
payload_too_large)
- Request body too large (
- 415:
- Unsupported media type (
unsupported_media_type)
- Unsupported media type (
- 422:
- Segment rules invalid (
segment_invalid) - Validation failed (
validation_failed)
- Segment rules invalid (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
id (required) | text. |
name (required) | text. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
applied_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. |
revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
used_by (required) | an object. |
used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
archived_at (required) | a date and time (RFC 3339), or null. |
created_at (required) | a date and time (RFC 3339). |
updated_at (required) | a date and time (RFC 3339). |
What a 201 answers
| Field | What it is |
|---|---|
id (required) | text. |
name (required) | text. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
applied_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. |
revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
used_by (required) | an object. |
used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
archived_at (required) | a date and time (RFC 3339), or null. |
created_at (required) | a date and time (RFC 3339). |
updated_at (required) | a date and time (RFC 3339). |
Read a segment
GET /v1/segments/{segment_id}
Its applied rules, its draft if it has one, and how many scheduled emails name it.
Its API key needs segments:read.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
Answers
- 200: The segment
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found)
- Segment not found (
- 422:
- Validation failed (
validation_failed)
- Validation failed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
id (required) | text. |
name (required) | text. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
applied_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. |
revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
used_by (required) | an object. |
used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
archived_at (required) | a date and time (RFC 3339), or null. |
created_at (required) | a date and time (RFC 3339). |
updated_at (required) | a date and time (RFC 3339). |
Rename or archive a segment
PATCH /v1/segments/{segment_id}
Changes only what the body names. Archiving takes the segment off the lists and frees its name; its history stays, and it can’t be undone. A segment a scheduled email names can’t be archived (409 segment_in_use). Counts toward the account’s segment-change limit when it changes something, and when it renamed before its archive was refused: the rename is undone, but it ran.
Its API key needs segments:write.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
Request body
A application/json body.
| Field | What it is |
|---|---|
name | text, up to 100 characters. |
archived | true. Archive it. |
Answers
- 200: The segment as it now is
- 400:
- Malformed request (
malformed_request)
- Malformed request (
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found)
- Segment not found (
- 409:
- Segment name already in use (
segment_name_taken) - Segment in use (
segment_in_use)
- Segment name already in use (
- 413:
- Request body too large (
payload_too_large)
- Request body too large (
- 415:
- Unsupported media type (
unsupported_media_type)
- Unsupported media type (
- 422:
- Validation failed (
validation_failed)
- Validation failed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
id (required) | text. |
name (required) | text. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
applied_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. |
revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
used_by (required) | an object. |
used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
archived_at (required) | a date and time (RFC 3339), or null. |
created_at (required) | a date and time (RFC 3339). |
updated_at (required) | a date and time (RFC 3339). |
Delete a segment
DELETE /v1/segments/{segment_id}
Deletes an archived segment and its versions, for good: archive it first (409 segment_not_archived otherwise). One any send named, sent or cancelled, or a campaign email names (its draft, or a version of it), stays archived (409 segment_in_use): the email keeps it. Counts toward the account’s segment-delete limit, unless it’s refused before the delete runs (404, or 409 segment_not_archived).
Its API key needs segments:write.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
Answers
- 204: Deleted
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found)
- Segment not found (
- 409:
- Archive the segment first (
segment_not_archived) - Segment in use (
segment_in_use)
- Archive the segment first (
- 422:
- Validation failed (
validation_failed)
- Validation failed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
Replace the rules
PUT /v1/segments/{segment_id}/rules
Applies the rules at once, unless a scheduled email that hasn't yet read a version names the segment (used_by.unpinned): then they're saved as its draft, and the email keeps resolving the applied rules until the draft is applied (issue 1581) or discarded. Rules equal to the applied ones end any draft. The rules are refused as 422 segment_invalid, with errors[0].pointer at the first rule refused and errors[0].code why, never the value: a shape the tree doesn’t take, a list, tag, or field the account doesn’t have, an operator the field’s type doesn’t take, a bound passed, or an engagement rule where engagement isn’t recorded yet. A retry of a change that already applied answers unchanged, whatever If-Match says. Counts toward the account’s segment-change limit, unless it answers unchanged or is refused.
Its API key needs segments:write.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
if-match | text, in the header. Required. The ETag you read, so the change applies only if nobody changed it since: 428 if_match_missing without it, and 412 revision_mismatch if it changed. * replaces it whatever it holds. A retry of a change that already applied succeeds, so after a timeout, retry with the same If-Match. |
Request body
A application/json body.
| Field | What it is |
|---|---|
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
Answers
- 200: Saved
- 400:
- Malformed request (
malformed_request)
- Malformed request (
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found)
- Segment not found (
- 412:
- Changed since you read it (
revision_mismatch)
- Changed since you read it (
- 413:
- Request body too large (
payload_too_large)
- Request body too large (
- 415:
- Unsupported media type (
unsupported_media_type)
- Unsupported media type (
- 422:
- Segment rules invalid (
segment_invalid) - Validation failed (
validation_failed)
- Segment rules invalid (
- 428:
- If-Match header needed (
if_match_missing)
- If-Match header needed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
outcome (required) | one of applied, drafted or unchanged. applied: the rules are the segment’s now (a new applied_version). drafted: a scheduled email still resolves the applied rules, so they went to draft, to apply or discard later. unchanged: the segment already held them. |
segment (required) | an object. A segment: rules are the applied rules, what a scheduled email resolves. draft holds a change saved while a scheduled email still resolves the applied rules (used_by.unpinned), until it’s applied or discarded; null otherwise. Names are unique in the account among the unarchived, ignoring case. |
segment.id (required) | text. |
segment.name (required) | text. |
segment.rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
segment.applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
segment.applied_at (required) | a date and time (RFC 3339). |
segment.draft (required) | an object, or null. |
segment.revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
segment.used_by (required) | an object. |
segment.used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
segment.used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
segment.archived_at (required) | a date and time (RFC 3339), or null. |
segment.created_at (required) | a date and time (RFC 3339). |
segment.updated_at (required) | a date and time (RFC 3339). |
Discard the draft
DELETE /v1/segments/{segment_id}/draft
Drops the draft; the applied rules stand. A segment with no draft answers 200 as it is, whatever If-Match says: a retry, or nothing to discard. Counts toward the account’s segment-change limit when it drops a draft.
Its API key needs segments:write.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
if-match | text, in the header. Required. The ETag you read, so the change applies only if nobody changed it since: 428 if_match_missing without it, and 412 revision_mismatch if it changed. A retry of a change that already applied succeeds, so after a timeout, retry with the same If-Match. |
Answers
- 200: The segment, with no draft
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found)
- Segment not found (
- 409:
- Segment has no draft (
segment_draft_missing)
- Segment has no draft (
- 412:
- Changed since you read it (
revision_mismatch)
- Changed since you read it (
- 422:
- Validation failed (
validation_failed)
- Validation failed (
- 428:
- If-Match header needed (
if_match_missing)
- If-Match header needed (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
id (required) | text. |
name (required) | text. |
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
applied_version (required) | a whole number. Numbered from 1 with each change of the applied rules. |
applied_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. |
revision (required) | a whole number. Moves with every change of the rules, the draft, or the name: the ETag. |
used_by (required) | an object. |
used_by.sends (required) | a whole number. How many scheduled emails (not yet gone) name the segment, as their audience or as an exclusion. While any does, the segment can’t be archived. |
used_by.unpinned (required) | a whole number. How many of those still resolve the applied rules when they go, rather than a version they’ve already read. While any does, a change to the rules goes to draft and waits for an apply (issue 1581). |
archived_at (required) | a date and time (RFC 3339), or null. |
created_at (required) | a date and time (RFC 3339). |
updated_at (required) | a date and time (RFC 3339). |
Count rules before saving them
POST /v1/segments/count
How many contacts the rules match, for a builder as rules are written. Counted now, over the eligible audience: active contacts with an address to send to, not on the account’s suppression list as far as the list can be matched (about: the send itself decides, so a count may include someone a send would leave out), and under a list only those whose consent to it is in force. Bounded: once it’s the count’s turn, its work shares 5 s, or what’s left of the request’s time if that’s less; past that it’s 422 segment_too_costly, and a request with no time left for a count is 503 segments_unavailable before it starts. One count at a time per account: a count waits at most 2 s for its turn, outside those 5 s, then it’s 503 segments_unavailable. A count answers from the account’s contacts, so a key needs contacts:read as well as segments:read. The rules are refused as 422 segment_invalid, with errors[0].pointer at the first rule refused and errors[0].code why, never the value: a shape the tree doesn’t take, a list, tag, or field the account doesn’t have, an operator the field’s type doesn’t take, a bound passed, or an engagement rule where engagement isn’t recorded yet.
Its API key needs segments:read and contacts:read.
Request body
A application/json body.
| Field | What it is |
|---|---|
rules (required) | an object. A rule tree, version 1: { "version": 1, "match": "all" | "any", "rules": [ … ] }, where each rule is a group (match and rules again) or a leaf with a kind and an op. The kinds: list (on, not_on, with list_id: a tpc_… id), tag (has, not_has, with tag_id), field (with field_id: is and is_not with a value of the field's type; less_than and greater_than with a number; before and after with a date as YYYY-MM-DD; in_last with days; is_set and is_not_set), clicked, not_clicked, and opened (in_last with days), joined (before, after, or in_last), and location (is, is_not, with a country as ISO 3166-1 alpha-2 and an optional region as ISO 3166-2). location reads the place a contact states first: the country set on the contact, then the person's own (a form's country field, a postal code). Only a contact with neither is placed by the country of a request they made, which is an estimate: the connection's country, not the person's. A stated country with no region takes the region from the next of those that names the same country, a request's included, and never takes another country. A language or a time zone places nobody. A negative matches a contact with no value. opened is an estimate: a mail app can open a message by itself, and a click counts as an open, so it has no negative. At most 30 leaves in a tree, 15 rules in a group, 3 levels, and in_last 3650 days; days count from midnight in the account's time zone. Anything else is 422 segment_invalid at the rule's JSON pointer. |
list_id | text. Count who would get an email to this list: consent to it in force, and nobody else. |
exclude_segment_id | text. Leave out everyone this segment’s applied rules match, as an email’s exclusion does. |
Answers
- 200: The count
- 400:
- Malformed request (
malformed_request)
- Malformed request (
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Topic not found (
topic_not_found) - Segment not found (
segment_not_found)
- Topic not found (
- 413:
- Request body too large (
payload_too_large)
- Request body too large (
- 415:
- Unsupported media type (
unsupported_media_type)
- Unsupported media type (
- 422:
- Segment rules invalid (
segment_invalid) - Segment too costly to count (
segment_too_costly) - Validation failed (
validation_failed)
- Segment rules invalid (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
matching (required) | a whole number. How many the rules match now, less any excluded. |
basis (required) | one of contacts or recipients. recipients under a list (list_id: who would get an email to it, their consent in force), contacts over the whole audience. Either way, a contact who isn’t active or has no address to send to isn’t counted. |
untracked (required) | a whole number, or null. How many of the eligible contacts an engagement rule can’t see (not tracked in full), who read as “didn’t click” or “didn’t open”; null when no rule reads engagement. |
first (required) | a list, each an object. The first five matches, newest first: names only, never an address. Every caller of a count may read contacts (a member, or a key with contacts:read, which a count needs). |
first[].id (required) | text. |
first[].name (required) | text, or null. |
first[].first_name (required) | text, or null. |
first[].last_name (required) | text, or null. |
definitions_version (required) | a whole number. Which engagement definitions the count read. |
counted_at (required) | a date and time (RFC 3339). |
A segment's counts
GET /v1/segments/{segment_id}/counts
How many contacts the segment's applied rules match, and its draft's, if it has one. Counted now, over the eligible audience: active contacts with an address to send to, not on the account’s suppression list as far as the list can be matched (about: the send itself decides, so a count may include someone a send would leave out), and under a list only those whose consent to it is in force. Bounded: once it’s the count’s turn, its work shares 5 s, or what’s left of the request’s time if that’s less; past that it’s 422 segment_too_costly, and a request with no time left for a count is 503 segments_unavailable before it starts. One count at a time per account: a count waits at most 2 s for its turn, outside those 5 s, then it’s 503 segments_unavailable. A count answers from the account’s contacts, so a key needs contacts:read as well as segments:read. A stored tree the account can no longer run (a tag or field deleted since, or an engagement rule where engagement isn't recorded) is 422 segment_invalid, with errors[0].pointer into the segment as GET shows it (/rules/… or /draft/…, with in: path).
Its API key needs segments:read and contacts:read.
Parameters
| Parameter | What it is |
|---|---|
segment_id (required) | text, up to 64 characters, in the path. The segment’s id (seg_…). |
list_id | text, in the query. Count who would get an email to this list: consent to it in force, and nobody else. |
exclude_segment_id | text, in the query. Leave out everyone this segment’s applied rules match, as an email’s exclusion does. |
Answers
- 200: The counts
- 401:
- API key missing (
api_key_missing) - Invalid API key (
api_key_invalid) - API key revoked (
api_key_revoked) - API key expired (
api_key_expired)
- API key missing (
- 403:
- Account closed (
account_closed) - Missing scope (
api_key_scope_missing) - Test keys can't do this (
test_key_not_allowed)
- Account closed (
- 404:
- Segment not found (
segment_not_found) - Topic not found (
topic_not_found)
- Segment not found (
- 422:
- Segment rules invalid (
segment_invalid) - Segment too costly to count (
segment_too_costly) - Validation failed (
validation_failed)
- Segment rules invalid (
- 429:
- Too many requests (
rate_limited)
- Too many requests (
- 500:
- Internal error (
internal)
- Internal error (
- 503:
- API keys unavailable (
api_keys_unavailable) - Segments unavailable (
segments_unavailable)
- API keys unavailable (
What a 200 answers
| Field | What it is |
|---|---|
revision (required) | a whole number. The segment’s revision these counts read: its ETag. A step that acts on what the counts showed (issue 1581’s apply) names it, so a change since then is refused rather than applied unseen. |
applied_version (required) | a whole number. The version applied read. |
applied (required) | an object. |
applied.matching (required) | a whole number. How many the rules match now, less any excluded. |
applied.basis (required) | one of contacts or recipients. recipients under a list (list_id: who would get an email to it, their consent in force), contacts over the whole audience. Either way, a contact who isn’t active or has no address to send to isn’t counted. |
applied.untracked (required) | a whole number, or null. How many of the eligible contacts an engagement rule can’t see (not tracked in full), who read as “didn’t click” or “didn’t open”; null when no rule reads engagement. |
applied.first (required) | a list, each an object. The first five matches, newest first: names only, never an address. Every caller of a count may read contacts (a member, or a key with contacts:read, which a count needs). |
applied.first[].id (required) | text. |
applied.first[].name (required) | text, or null. |
applied.first[].first_name (required) | text, or null. |
applied.first[].last_name (required) | text, or null. |
applied.definitions_version (required) | a whole number. Which engagement definitions the count read. |
applied.counted_at (required) | a date and time (RFC 3339). |
draft (required) | an object, or null. The draft’s count; null while the segment has no draft. |
draft.matching (required) | a whole number. How many the rules match now, less any excluded. |
draft.basis (required) | one of contacts or recipients. recipients under a list (list_id: who would get an email to it, their consent in force), contacts over the whole audience. Either way, a contact who isn’t active or has no address to send to isn’t counted. |
draft.untracked (required) | a whole number, or null. How many of the eligible contacts an engagement rule can’t see (not tracked in full), who read as “didn’t click” or “didn’t open”; null when no rule reads engagement. |
draft.first (required) | a list, each an object. The first five matches, newest first: names only, never an address. Every caller of a count may read contacts (a member, or a key with contacts:read, which a count needs). |
draft.first[].id (required) | text. |
draft.first[].name (required) | text, or null. |
draft.first[].first_name (required) | text, or null. |
draft.first[].last_name (required) | text, or null. |
draft.definitions_version (required) | a whole number. Which engagement definitions the count read. |
draft.counted_at (required) | a date and time (RFC 3339). |