# Preview a broadcast (variable coverage + sample)

`POST /v1/broadcasts/{id}/preview`

- Authentication: required (Bearer token)
- Required scope: `api.broadcasts.view`

Pre-send validation for a broadcast: the parallel to segment preview. For
the broadcast's pinned template version and resolved audience it
classifies every declared template variable (`attribute`, `reserved`, or
`unbound`) and computes per-variable coverage over the current audience
population — what fraction is resolved by a contact attribute, falls back
to `default_template_data`, or renders blank — plus a small rendered
sample.

Read-only: it never mutates the broadcast. Runs under the same ClickHouse
query governors segment preview uses. Returns `422 validation_failed` when
the template version has no renderable content or the audience cannot be
resolved (e.g. an invalid segment predicate); unresolved variables are
surfaced in the body, not raised.

## Path parameters

- `id` (string<uuid>, required) — Resource UUID. An unparseable id reads as a clean `404 not_found`.

## Example request

```bash
curl -X POST 'https://api.sendops.dev/v1/broadcasts/00000000-0000-0000-0000-000000000000/preview' \
  -H "Authorization: Bearer $SENDOPS_API_KEY"
```

## Responses

### 200 — The computed preview

Content type: `application/json`

```json
{
  "broadcast_id": "00000000-0000-0000-0000-000000000000",
  "audience": {
    "kind": "list",
    "id": "00000000-0000-0000-0000-000000000000",
    "total": 0
  },
  "variables": [
    {
      "variable": "string",
      "class": "attribute",
      "attribute_name": "string",
      "resolved_by_attribute": 0,
      "resolved_by_default": 0,
      "unresolved": 0,
      "coverage_percent": 0
    }
  ],
  "sample": {
    "available": true,
    "contact_id": "00000000-0000-0000-0000-000000000000",
    "email": "string",
    "subject": "string",
    "html": "string",
    "warnings": [
      "string"
    ]
  }
}
```

### 401 — Missing, malformed, or unknown API key

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 403 — Key lacks the required scope or plan limit violated

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 404 — Resource not found

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 422 — Query parameter or path value failed validation

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 429 — Per-org rate limit exceeded

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 500 — Unexpected server-side failure. The `code` is `internal_error`. The
`request_id` field can be quoted to SendOps support to investigate.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```
