# Update a template's draft (/docs/api-reference/email-templates/update-email-template-draft)

Replaces the draft's variables and content. Sends keep using the published version until the draft is published. Pass the `revision` you read to refuse overwriting someone else's changes. A draft with problems is saved (and reported in `problems`).

`PUT https://api.coss.com/v1/email_templates/{id}/draft`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Path parameters

- `id` (string, required): The template's id or alias.

## Request body

- `revision` (integer, at least 1): The draft `revision` you read. When given, the request is refused (`template_revision_mismatch`) if the draft changed since.
- `default_locale` (string, at most 35 characters): The locale sends fall back to when they ask for none, or for one without content. Defaults to the first entry of `contents` (or "en").
- `variables` (object[], at most 50 items): The variables the template uses, with their types.
  - `name` (string, required): Used in the template as `{{name}}`.
  - `type` ("string" | "number" | "boolean" | "list", required): `string`, `number`, `boolean`, or `list` (an array of objects with the declared `fields`, looped over with `{{#each name}}`).
  - `required` (boolean, default true): Sends must pass it unless it has a `default`. Defaults to true.
  - `default` (string | number | boolean): Used when a send leaves it out. Not for lists.
  - `description` (string, at most 500 characters): What it's for, shown in the dashboard.
  - `fields` (object[], 1-20 items): A list's item fields (required for lists, only for lists).
    - `name` (string, required): Used inside `{{#each}}` as `{{name}}`.
    - `type` ("string" | "number" | "boolean", required): The field's type.
    - `required` (boolean, default true): Whether each item must have it. Defaults to true.
- `sample_variables` (map of any): Example values for previews and test sends in the dashboard.
- `contents` (object[], at most 30 items): The subject, HTML and text per locale.
  - `locale` (string, required, at most 35 characters): The BCP 47 language tag this content is for, unique in `contents`.
  - `subject` (string, required, 1-2000 characters): The subject template.
  - `html` (string | null, at most 524288 characters): The HTML template. Provide `html`, `text`, or both.
  - `text` (string | null, at most 262144 characters): The plain-text template.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.email.templates.updateDraft("etpl_01k7c8m4q2f3e9v6t5r1n0p8yz", {
  revision: 3,
  default_locale: "en",
  variables: [
    {
      name: "first_name",
      type: "string",
      required: true,
    },
  ],
  sample_variables: {
    first_name: "Ada",
  },
  contents: [
    {
      locale: "en",
      subject: "Welcome, {{first_name}}",
      html: "<p>Hi {{first_name}}, thanks for signing up!</p>",
    },
    {
      locale: "de",
      subject: "Willkommen, {{first_name}}",
      html: "<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>",
    },
  ],
});
```

HTTP:

```sh
curl -X PUT "https://api.coss.com/v1/email_templates/etpl_01k7c8m4q2f3e9v6t5r1n0p8yz/draft" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "revision": 3,
  "default_locale": "en",
  "variables": [
    {
      "name": "first_name",
      "type": "string",
      "required": true
    }
  ],
  "sample_variables": {
    "first_name": "Ada"
  },
  "contents": [
    {
      "locale": "en",
      "subject": "Welcome, {{first_name}}",
      "html": "<p>Hi {{first_name}}, thanks for signing up!</p>"
    },
    {
      "locale": "de",
      "subject": "Willkommen, {{first_name}}",
      "html": "<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>"
    }
  ]
}'
```

Python:

```python
from coss import Coss
from coss import Coss, TemplateVariableInput, TemplateContentInput

client = Coss()  # api_key= or COSS_API_KEY

client.email.templates.update_draft(
    id="etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    revision=3,
    default_locale="en",
    variables=[
        TemplateVariableInput(
            name="first_name",
            type="string",
            required=True,
        )
    ],
    sample_variables={
        "first_name": "Ada"
    },
    contents=[
        TemplateContentInput(
            locale="en",
            subject="Welcome, {{first_name}}",
            html="<p>Hi {{first_name}}, thanks for signing up!</p>",
        ),
        TemplateContentInput(
            locale="de",
            subject="Willkommen, {{first_name}}",
            html="<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>",
        )
    ],
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
	email "github.com/cosscom/coss-go/email"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &email.UpdateEmailTemplateDraftRequest{
    ID: "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    Revision: coss.Int64(
        int64(3),
    ),
    DefaultLocale: coss.String(
        "en",
    ),
    Variables: []*coss.TemplateVariableInput{
        &coss.TemplateVariableInput{
            Name: "first_name",
            Type: coss.TemplateVariableInputTypeString,
            Required: coss.Bool(
                true,
            ),
        },
    },
    SampleVariables: map[string]any{
        "first_name": "Ada",
    },
    Contents: []*coss.TemplateContentInput{
        &coss.TemplateContentInput{
            Locale: "en",
            Subject: "Welcome, {{first_name}}",
            HTML: coss.String(
                "<p>Hi {{first_name}}, thanks for signing up!</p>",
            ),
        },
        &coss.TemplateContentInput{
            Locale: "de",
            Subject: "Willkommen, {{first_name}}",
            HTML: coss.String(
                "<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>",
            ),
        },
    },
}
client.Email.Templates.UpdateDraft(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.email.templates.update_draft(
  id: "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
  revision: 3,
  default_locale: "en",
  variables: [{
    name: "first_name",
    type: "string",
    required: true
  }],
  sample_variables: {
    first_name: "Ada"
  },
  contents: [{
    locale: "en",
    subject: "Welcome, {{first_name}}",
    html: "<p>Hi {{first_name}}, thanks for signing up!</p>"
  }, {
    locale: "de",
    subject: "Willkommen, {{first_name}}",
    html: "<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>"
  }]
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Email\Templates\Requests\UpdateEmailTemplateDraftRequest;
use Coss\Types\TemplateContentInput;
use Coss\Types\TemplateVariableInput;
use Coss\Types\TemplateVariableInputType;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->email->templates->updateDraft(
    'etpl_01k7c8m4q2f3e9v6t5r1n0p8yz',
    new UpdateEmailTemplateDraftRequest([
        'revision' => 3,
        'defaultLocale' => 'en',
        'variables' => [
            new TemplateVariableInput([
                'name' => 'first_name',
                'type' => TemplateVariableInputType::String->value,
                'required' => true,
            ]),
        ],
        'sampleVariables' => [
            'first_name' => "Ada",
        ],
        'contents' => [
            new TemplateContentInput([
                'locale' => 'en',
                'subject' => 'Welcome, {{first_name}}',
                'html' => '<p>Hi {{first_name}}, thanks for signing up!</p>',
            ]),
            new TemplateContentInput([
                'locale' => 'de',
                'subject' => 'Willkommen, {{first_name}}',
                'html' => '<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>',
            ]),
        ],
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.email.templates.requests.UpdateEmailTemplateDraftRequest;
import com.coss.types.TemplateContentInput;
import com.coss.types.TemplateVariableInput;
import com.coss.types.TemplateVariableInputType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.email().templates().updateDraft(
    "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    UpdateEmailTemplateDraftRequest
        .builder()
        .revision(3L)
        .defaultLocale("en")
        .variables(
            Optional.of(
                Arrays.asList(
                    TemplateVariableInput
                        .builder()
                        .name("first_name")
                        .type(TemplateVariableInputType.STRING)
                        .required(true)
                        .build()
                )
            )
        )
        .sampleVariables(
            new HashMap<String, Object>() {{
                put("first_name", "Ada");
            }}
        )
        .contents(
            Optional.of(
                Arrays.asList(
                    TemplateContentInput
                        .builder()
                        .locale("en")
                        .subject("Welcome, {{first_name}}")
                        .html(
                            OptionalNullable.of("<p>Hi {{first_name}}, thanks for signing up!</p>")
                        )
                        .build(),
                    TemplateContentInput
                        .builder()
                        .locale("de")
                        .subject("Willkommen, {{first_name}}")
                        .html(
                            OptionalNullable.of("<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>")
                        )
                        .build()
                )
            )
        )
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Email;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Email.Templates.UpdateDraftAsync(
    new UpdateEmailTemplateDraftRequest
    {
        Id = "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
        Revision = 3,
        DefaultLocale = "en",
        Variables = new List<TemplateVariableInput>()
        {
            new TemplateVariableInput
            {
                Name = "first_name",
                Type = TemplateVariableInputType.String,
                Required = true,
            },
        },
        SampleVariables = new Dictionary<string, object?>() { { "first_name", "Ada" } },
        Contents = new List<TemplateContentInput>()
        {
            new TemplateContentInput
            {
                Locale = "en",
                Subject = "Welcome, {{first_name}}",
                Html = "<p>Hi {{first_name}}, thanks for signing up!</p>",
            },
            new TemplateContentInput
            {
                Locale = "de",
                Subject = "Willkommen, {{first_name}}",
                Html = "<p>Hallo {{first_name}}, danke für deine Anmeldung!</p>",
            },
        },
    }
);
```

## Response 200

The saved draft.

- `object` ("email_template_version", required)
- `template_id` (string, required): The template's id.
- `version` (integer | null, required): The version number; `null` for the draft.
- `revision` (integer, required): Counts the draft's saves. A published version keeps the revision it was published from.
- `default_locale` (string, required): The locale sends fall back to when they ask for none, or for one without content.
- `variables` (object[], required): The variables the template uses, with their types.
  - `name` (string, required): Used in the template as `{{name}}`.
  - `type` ("string" | "number" | "boolean" | "list", required): `string`, `number`, `boolean`, or `list` (an array of objects with the declared `fields`).
  - `required` (boolean, required): Whether sends must pass it, unless it has a `default`.
  - `default` (string | number | boolean): Used when a send leaves it out.
  - `description` (string): What it's for, shown in the dashboard.
  - `fields` (object[]): A list's item fields.
    - `name` (string, required): Used inside `{{#each}}` as `{{name}}`.
    - `type` ("string" | "number" | "boolean", required): The field's type.
    - `required` (boolean, required): Whether each item must have it.
- `sample_variables` (map of any, required): Example values for previews and test sends in the dashboard.
- `contents` (object[], required): The subject, HTML and text per locale.
  - `locale` (string, required): The BCP 47 language tag this content is for.
  - `subject` (string, required): The subject template.
  - `html` (string | null, required): The HTML template. `null`: text only.
  - `text` (string | null, required): The plain-text template. `null`: HTML only.
- `problems` (object[], required): Syntax errors and undeclared variables per locale and field, which keep a draft from being published. Always empty for published versions.
  - `locale` (string, required): The locale whose content it's in.
  - `field` ("subject" | "html" | "text", required): The part of the content it's in.
  - `message` (string, required): What's wrong.
  - `line` (integer, required): The line it's on, from 1.
  - `column` (integer, required): The column it's at, from 1.
- `published_at` (string | null, required, date-time): When this version was published. `null` for the draft.
- `created_at` (string, required, date-time)
- `updated_at` (string, required, date-time)

Example:

```json
{
  "object": "email_template_version",
  "template_id": "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "version": 2,
  "revision": 3,
  "default_locale": "en",
  "variables": [
    {
      "name": "first_name",
      "type": "string",
      "required": true
    }
  ],
  "sample_variables": {
    "first_name": "Ada"
  },
  "contents": [
    {
      "locale": "en",
      "subject": "Welcome, {{first_name}}",
      "html": "<p>Hi {{first_name}}, thanks for signing up!</p>",
      "text": null
    }
  ],
  "problems": [],
  "published_at": "2026-10-10T12:00:00.000Z",
  "created_at": "2026-10-10T12:00:00.000Z",
  "updated_at": "2026-10-10T12:00:00.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: No template with this id or alias exists in the API key's environment (`not_found`).
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`), or the draft changed since `revision` (`template_revision_mismatch`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).