---
title: "Count contacts matching a rules tree"
method: POST
path: "/segments/preview"
tags: ["Segments"]
---

# Count contacts matching a rules tree

`POST /segments/preview`

## Request

- Base URL: `https://api.poststack.dev`
- URL: `https://api.poststack.dev/segments/preview`
- Auth: one of:
  - HTTP bearer
  - OAuth 2
    - Authorization code: `https://poststack.dev/oauth/authorize`
    - Token URL: `https://poststack.dev/oauth/token`
- TypeScript: <https://skmtc.dev/poststack/apis/poststack-api/docs/segments/preview/post.ts> (a function with typed inputs; its response is checked against the schema)

Nothing is saved.

## Request body

- PreviewSegmentRulesInput
  - `rules` object, required
    - `operator` 'and' | 'or', required
    - `conditions` object[], required
      - `field` string, required
      - `comparator` 'equals' | 'not_equals' | 'contains' | 'starts_with' | 'ends_with' | 'greater_than' | 'less_than' | 'greater_than_or_equal' | 'less_than_or_equal' | 'before' | 'after' | 'in_last_days' | 'is_set' | 'is_not_set', required
      - `value` string
      - `windowDays` integer

## Response `200`

Match count.

- object
  - `count` integer, required

## Other responses

- `400`: Validation failed — `error` names each offending field (`field: message`).
- `401`: Missing, malformed or unknown credentials (`WWW-Authenticate: Bearer …` is set).
- `403`: The credential lacks the `contacts:read` scope (body `{ error: "insufficient_scope", required, missing }`), or the team is suspended.
- `429`: Rate limited (10/min). `Retry-After` gives the seconds to wait; `X-RateLimit-*` headers are sent on every response.

## Changes

- **2026-09-30** `4dc1e20989c8`: 12 warning
  - added the new `daily_limit_exceeded` enum value to the `anyOf[#/components/schemas/Error]/code` response property for the response status `403`
  - added the new `daily_limit_exceeded` enum value to the `code` response property for the response status `400`
  - added the new `daily_limit_exceeded` enum value to the `code` response property for the response status `401`
  - added the new `daily_limit_exceeded` enum value to the `code` response property for the response status `429`
  - …8 more
- **2026-09-29** `ef5b22b98333`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/poststack/apis/poststack-api/changes/segments/preview/post.md)

---

[API](https://skmtc.dev/poststack/apis/poststack-api.md) - [All operations](https://skmtc.dev/poststack/apis/poststack-api/llms.txt) - [OpenAPI document](https://skmtc.dev/poststack/apis/poststack-api/revisions/0d3971e3a670?raw)
