# Preview segment rules

`POST /v1/segments/preview`

Requires an API key with the `segments:read` scope. [About keys and scopes](/docs/api/authentication)

Evaluates a rule tree that has not been saved and returns who it would match. Use this to check a segment definition before creating it.

## Request body

- `rules` (object, required) — The unsaved rule tree to evaluate.
  - One of: **Match all**
    - `all` (object[], required, at least 1 item, at most 20 items) — Every rule or nested group must match.
  - One of: **Match any**
    - `any` (object[], required, at least 1 item, at most 20 items) — At least one rule or nested group must match.

## Returns

Returns `200 OK` with a `AudienceCount` in `data`. Otherwise returns an error; [Errors](/docs/api/errors) lists every code and which to retry.

- `count` (integer, required, min 0, max 9007199254740991) — Contacts the rules match, counted up to 10000.
- `countExact` (boolean, required) — False when `count` is the cap and more contacts match.

## Example

```bash
curl -X POST https://api.kirora.io/v1/segments/preview \
  -H "Authorization: Bearer $KIRORA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "rules": {
      "all": [
        {
          "type": "attribute",
          "field": "field_example",
          "operator": "equals"
        }
      ]
    }
  }'
```

Response `200`:

```json
{
  "data": {
    "count": 0,
    "countExact": true
  }
}
```
