# API reference: Templates

> Endpoints of the Templates group of the Sendtide API with parameters, request body, responses and curl examples.

URL: https://sendtide.ch/en/docs/api/templates/

11 endpoints of the Templates group.
## List templates

GET /v1/templates
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| limit | query | integer | Page size. The default and the maximum depend on the endpoint (emails 50 up to 500, received mail 50 up to 200, audit up to 200, the others 100 up to 500 or 1000). Default: 100 |
| cursor | query | string | The next_cursor of the previous page. Opaque; pass it unchanged to the same endpoint with the same filters. |
### Example

```
curl "https://api.sendtide.ch/v1/templates" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Templates |
## Create a template

POST /v1/templates
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| alias | string | |
| name | string | |
| kind | enum: visual / code | |
| style | object | |
| langs | object | |
| sub_allow | boolean | |
| publish | boolean | |
| note | string | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/templates" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"alias":"welcome","name":"Willkommen","kind":"code","langs":{"de-CH":{"subject":"Willkommen, {{ data.name }}","html":"<p>Hallo {{ data.name }}</p>"}},"publish":true}'
```
### Responses
| Status | Description |
| --- | --- |
| 201 | Created Template |
| 409 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
| 422 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
## Get a template (draft and published version)

GET /v1/templates/{id}
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Example

```
curl "https://api.sendtide.ch/v1/templates/welcome" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | The template Template |
## Change the draft (publish with "publish": true)

PATCH /v1/templates/{id}
A language set to null is removed. Sending always uses the published version.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| alias | string | |
| name | string | |
| kind | enum: visual / code | |
| style | object | |
| langs | object | |
| sub_allow | boolean | |
| publish | boolean | |
| note | string | |
### Example

```
curl -X PATCH "https://api.sendtide.ch/v1/templates/welcome" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"langs":{"de-CH":{"subject":"Willkommen, {{ data.name }}"}},"publish":true}'
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Updated Template |
## Delete a template

DELETE /v1/templates/{id}
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Example

```
curl -X DELETE "https://api.sendtide.ch/v1/templates/welcome" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 204 | Deleted |
## Publish the draft as a new version

POST /v1/templates/{id}/publish
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| note | string | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/templates/welcome/publish" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Published Template |
## Render a preview with data

POST /v1/templates/{id}/render
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| data | object | |
| locale | string | |
| version | string | "draft", "published" or a version number Default: "draft" Example: 3 |
| content | TemplateVersion | Unsaved working copy to render instead of a stored version |
| content.kind | enum: visual / code | |
| content.style | object | |
| content.style.accent | string | |
| content.style.bg | string | |
| content.style.font | string | |
| content.style.width | integer | |
| content.langs | object | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/templates/welcome/render" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"version":"3"}'
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Rendered |
## Send a test mail

POST /v1/templates/{id}/test
Renders the template and sends one mail with "[Test]" before the subject. Needs a key with send rights.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Request body application/json
| Field | Type | Description |
| --- | --- | --- |
| from * | string | Example: Shop |
| to * | string (email) | |
| data | object | |
| locale | string | |
| version | string | "draft" (default), "published" or a version number |
| content | TemplateVersion | Unsaved working copy |
| content.kind | enum: visual / code | |
| content.style | object | |
| content.style.accent | string | |
| content.style.bg | string | |
| content.style.font | string | |
| content.style.width | integer | |
| content.langs | object | |
| attachments | array | Files sent with the test mail |
| attachments[].filename * | string | Sanitized: path and control characters are removed. Executable and script files are refused. Example: rechnung.pdf |
| attachments[].content * | string (base64) | |
| attachments[].content_type | string | Taken from the file extension if missing Example: application/pdf |
| attachments[].content_id | string | Makes the file an inline image; the HTML refers to it as src="cid:logo" Example: logo |
| attachments[].disposition | enum: attachment / inline | Default inline with a content_id, else attachment |
| stream | string | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/templates/welcome/test" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"from":"Shop <hallo@example.ch>","to":"anna@example.com"}'
```
### Responses
| Status | Description |
| --- | --- |
| 202 | Queued EmailAccepted |
| 422 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
## List published versions, newest first

GET /v1/templates/{id}/versions
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
### Example

```
curl "https://api.sendtide.ch/v1/templates/welcome/versions" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Versions |
## Get one version with its content

GET /v1/templates/{id}/versions/{version}
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
| version * | path | string | A number or "published" |
### Example

```
curl "https://api.sendtide.ch/v1/templates/welcome/versions/3" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | The version TemplateVersionInfo |
| 404 | Error in the usual format, [errors and limits](https://sendtide.ch/en/docs/errors-and-limits/) |
## Copy a version into the draft

POST /v1/templates/{id}/versions/{version}/restore
The published version stays until the draft is published again.
### Parameters
| Name | In | Type | Description |
| --- | --- | --- | --- |
| id * | path | string | |
| version * | path | string | |
### Example

```
curl -X POST "https://api.sendtide.ch/v1/templates/welcome/versions/3/restore" \
  -H "Authorization: Bearer sk_test_…"
```
### Responses
| Status | Description |
| --- | --- |
| 200 | Draft restored Template |
