Preview a filter
POST/api/v1/segments/preview
POST /segments/preview
curl -X POST 'https://www.unitpost.com/api/v1/segments/preview' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'User-Agent: my-app/1.0' \
-H 'Content-Type: application/json' \
-d '{
"filter": {
"match": "all",
"conditions": [
{
"field": "plan",
"operator": "eq",
"value": "pro"
}
]
}
}'Response · 200
{
"object": "segment_preview",
"segment_id": "segment_123",
"archived": false,
"member_count": 1,
"subscribed_count": 1,
"sample": [
{
"id": "id_123",
"email": "customer@example.com",
"first_name": "string",
"last_name": "string"
}
]
}Count an unsaved dynamic filter before you create the segment, as the segment dialog's live count does: how many contacts match, how many of them a campaign would mail, and a sample (which also needs contacts:read). It reads with the same filter builder the send uses. Nothing is saved. Requires the segments:read capability.
Request body1 field
| Field | Type | Description |
|---|---|---|
filterrequired | object | The filter to count, as a dynamic segment's `filter`. Dynamic segments only: the saved filter, evaluated live. A condition on a custom field uses the field's default_value for any contact with no value (key missing or null), the same value merge tags use; defaults are never written onto contacts. is_set / is_not_set check whether the contact itself has a value. |
Response · 200 fields6 fields
| Field | Type | Description |
|---|---|---|
objectrequired | string | — |
segment_idrequired | string | null | The saved segment, or null for an unsaved filter. |
archivedrequired | boolean | null | Whether the saved segment is archived (a campaign can't target it); null for an unsaved filter. |
member_countrequired | integer | Contacts that match (or are members). |
subscribed_countrequired | integer | Of those, the ones a campaign would mail: not unsubscribed. 0 means an empty send. |
samplerequired | object[] | Up to 3 of the subscribed set. Empty without `contacts:read`. |
200400401403422