# API-Referenz: Vorlagen

> Endpunkte der Gruppe «Vorlagen» der Sendtide API mit Parametern, Request-Body, Antworten und curl-Beispielen. Die Referenz ist auf Englisch.

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

11 Endpunkte der Gruppe «Vorlagen». Die Referenz stammt aus der englischen OpenAPI-Spezifikation und ist nicht übersetzt.
## List templates

GET /v1/templates
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| 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. |
### Beispiel

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

POST /v1/templates
### Request-Body application/json
| Feld | Typ | Beschreibung |
| --- | --- | --- |
| alias | string | |
| name | string | |
| kind | enum: visual / code | |
| style | object | |
| langs | object | |
| sub_allow | boolean | |
| publish | boolean | |
| note | string | |
### Beispiel

```
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}'
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 201 | Created Template |
| 409 | Fehler im üblichen Format, [Fehler und Limits](https://sendtide.ch/docs/fehler-und-limits/) |
| 422 | Fehler im üblichen Format, [Fehler und Limits](https://sendtide.ch/docs/fehler-und-limits/) |
## Get a template (draft and published version)

GET /v1/templates/{id}
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Beispiel

```
curl "https://api.sendtide.ch/v1/templates/welcome" \
  -H "Authorization: Bearer sk_test_…"
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 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.
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Request-Body application/json
| Feld | Typ | Beschreibung |
| --- | --- | --- |
| alias | string | |
| name | string | |
| kind | enum: visual / code | |
| style | object | |
| langs | object | |
| sub_allow | boolean | |
| publish | boolean | |
| note | string | |
### Beispiel

```
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}'
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 200 | Updated Template |
## Delete a template

DELETE /v1/templates/{id}
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | Alias or tpl_ id |
### Beispiel

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

POST /v1/templates/{id}/publish
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
### Request-Body application/json
| Feld | Typ | Beschreibung |
| --- | --- | --- |
| note | string | |
### Beispiel

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

POST /v1/templates/{id}/render
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
### Request-Body application/json
| Feld | Typ | Beschreibung |
| --- | --- | --- |
| 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 | |
### Beispiel

```
curl -X POST "https://api.sendtide.ch/v1/templates/welcome/render" \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"version":"3"}'
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 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.
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
### Request-Body application/json
| Feld | Typ | Beschreibung |
| --- | --- | --- |
| 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 | |
### Beispiel

```
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"}'
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 202 | Queued EmailAccepted |
| 422 | Fehler im üblichen Format, [Fehler und Limits](https://sendtide.ch/docs/fehler-und-limits/) |
## List published versions, newest first

GET /v1/templates/{id}/versions
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
### Beispiel

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

GET /v1/templates/{id}/versions/{version}
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
| version * | path | string | A number or "published" |
### Beispiel

```
curl "https://api.sendtide.ch/v1/templates/welcome/versions/3" \
  -H "Authorization: Bearer sk_test_…"
```
### Antworten
| Status | Beschreibung |
| --- | --- |
| 200 | The version TemplateVersionInfo |
| 404 | Fehler im üblichen Format, [Fehler und Limits](https://sendtide.ch/docs/fehler-und-limits/) |
## Copy a version into the draft

POST /v1/templates/{id}/versions/{version}/restore
The published version stays until the draft is published again.
### Parameter
| Name | Ort | Typ | Beschreibung |
| --- | --- | --- | --- |
| id * | path | string | |
| version * | path | string | |
### Beispiel

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