Segments
Create dynamic audience segments based on contact attributes, behavior, and engagement data.
GET
/segmentsList all segments with optional filtering and pagination.
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| search | string | Optional | Search segments by name. |
| limit | integer | Optional | Number of segments to return (default: 100, max: 1000). |
| offset | integer | Optional | Number of segments to skip for pagination (default: 0). |
curl "https://api.topmail.so/api/v1/segments?search=vip&limit=10" \-H "Authorization: Bearer tm_live_abc123"
GET
/segments/:idRetrieve a single segment by ID.
curl https://api.topmail.so/api/v1/segments/SEGMENT_ID \-H "Authorization: Bearer tm_live_abc123"
POST
/segmentsCreate a new segment.
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | Required | Segment name (max 100 characters). |
| conditions | object | Optional | Segment conditions with match mode ("all" or "any") and an array of rules. |
curl -X POST https://api.topmail.so/api/v1/segments \-H "Authorization: Bearer tm_live_abc123" \-H "Content-Type: application/json" \-d '{"name": "Engaged Subscribers","conditions": {"match": "all","rules": [{"field": "engagement_score", "operator": "gte", "value": 50},{"field": "subscribed", "operator": "equals", "value": true}]}}'
PATCH
/segments/:idUpdate a segment. Only provided fields are modified.
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | Optional | Updated segment name. |
| conditions | object | Optional | Updated segment conditions. |
curl -X PATCH https://api.topmail.so/api/v1/segments/SEGMENT_ID \-H "Authorization: Bearer tm_live_abc123" \-H "Content-Type: application/json" \-d '{"name": "Top Engaged Subscribers"}'
DELETE
/segments/:idPermanently delete a segment.
curl -X DELETE https://api.topmail.so/api/v1/segments/SEGMENT_ID \-H "Authorization: Bearer tm_live_abc123"
POST
/segments/:id/estimateGet an estimated count of contacts matching the segment conditions.
curl -X POST https://api.topmail.so/api/v1/segments/SEGMENT_ID/estimate \-H "Authorization: Bearer tm_live_abc123"
GET
/segments/:id/contactsList contacts matching the segment conditions with pagination.
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| limit | integer | Optional | Number of contacts to return (default: 100, max: 1000). |
| offset | integer | Optional | Number of contacts to skip for pagination (default: 0). |
curl "https://api.topmail.so/api/v1/segments/SEGMENT_ID/contacts?limit=50" \-H "Authorization: Bearer tm_live_abc123"
Condition Operators
Segment conditions support the following operators for building rules:
equalsExact matchnot_equalsNot equalcontainsString containsgtGreater thanltLess thangteGreater than or equallteLess than or equalin_last_daysWithin N daysmore_than_days_agoOlder than N daysexactly_days_agoExactly N days agois_setField has a valueis_not_setField is emptyin_listValue in arraynot_in_listValue not in array