---
title: "Preview a filter"
description: "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). `POST /api/v1/segments/preview`"
url: https://www.unitpost.com/docs/platform/post-segments-preview
section: "Platform API reference"
updated: 2026-10-13
---
# Preview a filter

`POST /api/v1/segments/preview`

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 body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `filter` | object | yes | 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 fields (200)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | — |
| `segment_id` | string \| null | yes | The saved segment, or null for an unsaved filter. |
| `archived` | boolean \| null | yes | Whether the saved segment is archived (a campaign can't target it); null for an unsaved filter. |
| `member_count` | integer | yes | Contacts that match (or are members). |
| `subscribed_count` | integer | yes | Of those, the ones a campaign would mail: not unsubscribed. 0 means an empty send. |
| `sample` | object[] | yes | Up to 3 of the subscribed set. Empty without `contacts:read`. |

## Responses

| Status | Description |
| --- | --- |
| 200 | The counts. |
| 400 | The body isn't JSON. |
| 401 | Missing or invalid API key. |
| 403 | Insufficient scope. |
| 422 | A bad `filter`, or an unknown key. |

## Example request

```bash
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"
        }
      ]
    }
  }'
```

## Example response (200)

```json
{
  "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"
    }
  ]
}
```

## Links

- HTML reference (with Node.js, Python, Ruby, PHP, Laravel, Go, Java, Rust, .NET and CLI examples): https://www.unitpost.com/docs/platform/post-segments-preview
- OpenAPI 3.1 (full schemas): https://www.unitpost.com/api/v1/openapi.json
