# Read template

`GET https://postcraft.io/api/v1/templates/{id}`

Returns the template metadata, the stored code and styles, the example context (parsed JSON value), the block tree (null in code mode), and the folder it is filed under (null at the root). Reads the published copy (what `/render` serves) unless `stage=draft` asks for work in progress.

## Authentication

Send one of these headers:

- `x-api-key: <key>`: Long-lived account credential. Create one from the dashboard.
- `Authorization: Bearer <token>`: Short-lived presigned token scoped to a single template (minted via /presigned-url).

## Parameters

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `id` | path | string | yes |  |
| `stage` | query | `"draft"`, `"published"` | no | Which copy to read. `published` (the default) is what renders; `draft` is work in progress, and falls back to the published copy when there is none. |

## Responses

### 200

Template found.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `template` | object | yes |  |
| `code` | string | yes |  |
| `styles` | string | yes |  |
| `exampleContext` | object | yes | Structural JSON value: object or array. Scalars and null are rejected. |
| `blocks` | object or null | yes |  |
| `subject` | string or null | yes | Subject line as stored (Handlebars), or null when none is set. |
| `folder` | object or null | yes | Where the template is filed (id + normalized path), or null at the root. |
| `diagnostics` | object[] | yes | Problems found in the template. Advisory rather than fatal: a template that renders can still carry warnings, while an `error` severity is one that will not. |

### Errors

Every error answers with `{ "error": { "code": string, "message": string } }`.

| Status | Meaning |
| ------ | ------- |
| 400 | Invalid input. |
| 401 | Missing or invalid credential. |
| 403 | Authenticated but not allowed. |
| 404 | Not found. |
| 413 | Payload exceeds size limit. |
| 422 | Template render failed. |
| 429 | Rate limited. |

The whole API as an OpenAPI document: https://postcraft.io/api/v1/openapi.json
