Segments API
A segment is a saved group of an audience's subscribers, defined by rules. Its id is what segment_id takes in a newsletter block's visibility. Only subscribed members are counted and sent to.
Last updated
The segment object
matching_count is how many subscribed members the definition matches now.
{
"object": "segment",
"id": "nwsseg_abc123",
"audience_id": "aud_abc123",
"name": "Founders",
"definition": {
"match": "all",
"rules": [
{ "kind": "merge_field", "field": "role", "operator": "equals", "value": "founder" },
{ "kind": "last_sign_of_life", "operator": "within_days", "value": 90 }
]
},
"matching_count": 128,
"created_at": "2026-11-03T09:00:00.000Z",
"updated_at": "2026-11-03T09:00:00.000Z"
}List and get segments
/v1/audiences/:id/segmentsscope audiences:read/v1/audiences/:id/segments/:segmentIdscope audiences:readThe list returns { data: [segment] }, sorted by name and not paginated. An audience or segment outside your organization answers 404, and a key limited to other audiences gets a 403.
Create and update a segment
/v1/audiences/:id/segmentsscope audiences:write/v1/audiences/:id/segments/:segmentIdscope audiences:writeCreate takes a name (1 to 120 characters, unique within the audience, or a 409) and a definition, and answers 201. It accepts an Idempotency-Key. Update takes either field or both; an omitted field keeps its value. An issue already scheduled keeps the membership fixed when it was scheduled.
A definition has match (all rules or any rule) and 1 to 10 rules:
merge_field: afieldof lowercase letters, digits and underscores, withequals,not_equals,containsornot_containsand avaluecompared without case, oris_setandis_not_setwith no value. Negative rules only match fields that have a value.join_date:before,after,on_or_beforeoron_or_afteraYYYY-MM-DDday in UTC.engagement_tier:isoris_notengaged,cooling,cold,dormantornot_enough_data.last_sign_of_life:within_daysornot_within_days, 1 to 3650 days. A subscriber with no sign of life ever matchesnot_within_days.issues_received:at_leastorat_most, 0 to 100,000 newsletters.
Delete a segment
/v1/audiences/:id/segments/:segmentIdscope audiences:writeAnswers 204. A newsletter that sends to the segment holds it, whatever its status, sent issues included: the delete answers 409 and nothing changes. A block limited to the segment does not hold it. The delete succeeds, an unsent draft then fails the Block segments preflight check and cannot be scheduled until you change the block, and an issue already scheduled keeps the membership fixed when it was scheduled.
SDKs, CLI and MCP
const segment = await shipmail.audiences.segments.create("aud_abc123", {
name: "Founders",
definition: {
match: "all",
rules: [{ kind: "merge_field", field: "role", operator: "equals", value: "founder" }],
},
});
const { data } = await shipmail.audiences.segments.list("aud_abc123");
await shipmail.audiences.segments.update("aud_abc123", segment.id, { name: "All founders" });
await shipmail.audiences.segments.delete("aud_abc123", segment.id);segment = client.audiences.segments.create(
"aud_abc123",
{
"name": "Founders",
"definition": {
"match": "all",
"rules": [{"kind": "merge_field", "field": "role", "operator": "equals", "value": "founder"}],
},
},
)
client.audiences.segments.update("aud_abc123", segment["id"], {"name": "All founders"})shipmail audiences segments list aud_abc123
shipmail audiences segments create aud_abc123 --name Founders --definition @segment.json
shipmail audiences segments update aud_abc123 nwsseg_abc123 --name "All founders"
shipmail audiences segments delete aud_abc123 nwsseg_abc123MCP tools: shipmail_list_audience_segments, shipmail_create_audience_segment, shipmail_get_audience_segment, shipmail_update_audience_segment and shipmail_delete_audience_segment.