# Preview a template

https://docs.sendsms.to/en/api/preview-template/

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

Preview uses the rendering function used by sending. Samples are for preview only. No SMS is sent and no money is reserved.

Required permission: templates.read

## Parameters

- `id` (path, required): 
- `X-Dry-Run` (header, optional): Optional. true — a trial request: every check of the real request is made (key, IP allowlist, permission, account, fields, sender, template, parts, price, funds), but nothing is executed — no message, no reservation, no queue, no data change, the Idempotency-Key is not taken. The answer has the real status and structure plus dryRun: true; identifiers in it are conditional (zero UUID). Refusals are the real ones. Any other value — 400 invalid_dry_run. Trial requests have their own, lower rate limit.

## Request body

| Field | Type | Description |
| --- | --- | --- |
| `variables` | object | optional. Template variable values by name. Required for every required variable of the template unless useSamples is true. |
| `to` | string | optional. Recipient number for the preview; fills {{phone}}. Optional. |
| `useSamples` | boolean | optional. true fills missing variables with their sample values and lists them in substituted. |

## Request example

```bash
curl --max-time 30 --request POST \
  --url 'https://api.sendsms.to/v1/templates/TEMPLATE_ID/preview' \
  --header "X-API-Key: $SENDSMS_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "variables": {
    "order_id": "A-10492"
  }
}'
```

## Responses

### HTTP 200 — Successful result

```json
{
  "text": "Hello Aygun",
  "encoding": "GSM-7",
  "parts": 1,
  "length": 11,
  "trafficClass": "transactional",
  "substituted": [],
  "version": 1
}
```

| Field | Type | Description |
| --- | --- | --- |
| `text` | string | required. Final preview text rendered by SendSMS from the stored template and supplied/sample values. Preview does not send. |
| `encoding` | string | required. Encoding calculated by SendSMS from preview text: GSM-7 or Unicode (UCS-2). Not chosen by the client. |
| `parts` | integer | required. Number of SMS segments calculated by SendSMS for the rendered text, not the number of recipients. Multipart boundaries depend on encoding. |
| `length` | integer | required. Length calculated by SendSMS: GSM-7 septets (extension characters count twice) or UCS-2/UTF-16 code units. Not bytes or necessarily the visible character count. |
| `trafficClass` | string | null | required. Traffic class supplied by the customer and stored by SendSMS; null means none is pinned in the template. This does not override account permissions. |
| `substituted` | array<string> | required. Variable names for which SendSMS used samples because useSamples=true and real values were missing. Empty means no samples substituted. |
| `version` | integer | required. Stored template version used by SendSMS for this preview. Save it when comparing preview results with a later template edit. |
| `dryRun` | boolean | optional. Present only in the answer to a trial request (X-Dry-Run: true): nothing was executed; identifiers in this answer are conditional. |

### HTTP 400 — Invalid input

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |

### HTTP 401 — Invalid or revoked API key

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |

### HTTP 403 — Insufficient key permissions or account/channel policy; or the request came from an IP address not allowed for this key (ip_not_allowed)

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |

### HTTP 404 — Resource unavailable to this account

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |

### HTTP 409 — Conflict

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |

### HTTP 422 — Validation or eligibility failure

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |

### HTTP 429 — Rate limit

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |

### HTTP 503 — Temporarily unavailable

```json
{
  "error": "string"
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | required. Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
| `message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `code` | string | optional. Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
| `statusCode` | integer | optional. Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
| `errors` | array<object> | optional. Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
| `errors[].field` | string | optional. Request field identified by the SendSMS validator, such as name or body. |
| `errors[].message` | string | optional. Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
| `missing` | array<string> | optional. Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
| `invalid` | array<object> | optional. Invalid variable values identified by SendSMS, with variable name and validation reason. |
| `invalid[].name` | string | optional. Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
| `invalid[].reason` | string | optional. SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
| `channel` | string | optional. Requested channel echoed by SendSMS in a channel-availability refusal. |
| `reasons` | array<string> | optional. SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
