# Restore a template version (/docs/api-reference/email-templates/restore-email-template-version)

Replaces the draft with a published version's variables and content. Publish the draft to make sends use it again.

`POST https://api.coss.com/v1/email_templates/{id}/versions/{version}/restore`

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.
- `version` (integer, required, at least 1): A published version number.

## 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.versions.restore("etpl_01k7c8m4q2f3e9v6t5r1n0p8yz", 1);
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/email_templates/etpl_01k7c8m4q2f3e9v6t5r1n0p8yz/versions/1/restore" \
  -H "Authorization: Bearer $COSS_API_KEY"
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.email.templates.versions.restore(
    id="etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    version=1,
)
```

Go:

```go
import (
	"context"

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

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

request := &templates.RestoreVersionsRequest{
    ID: "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    Version: int64(1),
}
client.Email.Templates.Versions.Restore(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.email.templates.versions.restore(
  id: "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
  version: 1
)
```

PHP:

```php
<?php

use Coss\Coss;

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

$client->email->templates->versions->restore(
    'etpl_01k7c8m4q2f3e9v6t5r1n0p8yz',
    1,
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.email.templates.versions.requests.RestoreVersionsRequest;

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

client.email().templates().versions().restore(
    "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz",
    1L,
    RestoreVersionsRequest
        .builder()
        .build()
);
```

.NET:

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

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

await client.Email.Templates.Versions.RestoreAsync(
    new RestoreVersionsRequest { Id = "etpl_01k7c8m4q2f3e9v6t5r1n0p8yz", Version = 1 }
);
```

## Response 200

The 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 `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`).
- `422`: The template has no such version (`template_version_not_found`).
- `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`).