# Templates API

> Create template versions, publish one per alias, and use them when sending.

Base URL: `https://api.emailit.com/v2`. Authenticate with `Authorization: Bearer <API key>`.

## Create a template — POST /templates

> Create a template version under an alias. A new alias is published right away; a version for an existing alias starts as an unpublished draft.

# Create a template

Creates a template version. Versions that share an `alias` belong to the same template, and only one version per alias is published at a time. When you [send an email](/docs/api-reference/emails/send/) with `template` set to an alias, Emailit uses the published version. Requires an API key with `full` scope.

`POST /templates`

## Request body

- `name` (string, required): Template name shown in the dashboard. Up to 191 characters.

- `alias` (string, required): Identifier that groups the versions of a template. Up to 191 characters; lowercase letters, numbers, underscores and hyphens only (`^[a-z0-9_-]+$`). If no template uses this alias yet, the new version is published immediately. If the alias already exists, the new version is created unpublished (`published_at` is `null`) and you publish it with [Publish a template](/docs/api-reference/templates/publish/).

- `from` (string): Default sender, for example `Acme <hello@acme.com>`. Up to 191 characters.

- `subject` (string): Default subject line. Up to 191 characters. Can contain [Temple](/docs/templates/temple/) variables such as `{{ first_name }}`.

- `reply_to` (string | string[]): Reply-to address, or an array of addresses. Every value must be a valid email address.

- `html` (string): HTML body.

- `text` (string): Plain-text body.

- `source` (string): Editor source document, for example the Dragit JSON of a template built in the drag-and-drop editor. Stored as-is. For `editor: "mjml"`, the MJML: Emailit validates it, stores it as an [MJML document](/docs/templates/mjml/#the-stored-document) and compiles `html` from it.

- `editor` (string): Editor the template belongs to: `html` (default), `text`, `dragit` or `tiptap`. `mjml` is in alpha and open to the Emailit team only; other requests get `403` with `error: "mjml_alpha"`. See [MJML editors and API](/docs/templates/mjml/).

## Returns

Returns `201 Created` with the template in `data` and a confirmation `message`. The template includes `html`, `text` and `source`. Emailit also sends a [`template.created`](/docs/webhooks/events/template/created/) webhook event.

MJML templates also return an `mjml` object with the document's versions. Invalid MJML returns `422` with `errors.source` and `diagnostics`; see [Validation](/docs/templates/mjml/#validation).

If a field fails validation, the response is `400` with `message: "Validation failed"` and an `errors` object keyed by field, for example an alias with uppercase letters or an invalid `reply_to` address. A missing `name` or `alias`, or an `editor` value that isn't allowed, returns the standard `400` validation error with a `details` array instead. See [Errors](/docs/api-reference/errors/).

**Request** `POST /templates`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

const template = await emailit.templates.create({
  name: 'Welcome email',
  alias: 'welcome-email',
  subject: 'Welcome to Acme, {{ first_name }}',
  html: '<h1>Welcome, {{ first_name }}</h1>'
});
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

template = client.templates.create({
    "name": "Welcome email",
    "alias": "welcome-email",
    "subject": "Welcome to Acme, {{ first_name }}",
    "html": "<h1>Welcome, {{ first_name }}</h1>"
})
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$template = $emailit->templates()->create([
    'name' => 'Welcome email',
    'alias' => 'welcome-email',
    'subject' => 'Welcome to Acme, {{ first_name }}',
    'html' => '<h1>Welcome, {{ first_name }}</h1>'
]);
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

template = client.templates.create(
  name: "Welcome email",
  alias: "welcome-email",
  subject: "Welcome to Acme, {{ first_name }}",
  html: "<h1>Welcome, {{ first_name }}</h1>"
)
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

template, err := client.Templates.Create(&emailit.CreateTemplateRequest{
    Name:    "Welcome email",
    Alias:   "welcome-email",
    Subject: "Welcome to Acme, {{ first_name }}",
    Html:    "<h1>Welcome, {{ first_name }}</h1>",
})
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

let template = emailit.templates.create(
    emailit::types::CreateTemplateParams::new("Welcome email")
        .with_subject("Welcome to Acme, {{ first_name }}")
        .with_html("<h1>Welcome, {{ first_name }}</h1>")
).await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

EmailitObject template = emailit.templates().create(
    TemplateCreateParams.builder()
        .setName("Welcome email")
        .setAlias("welcome-email")
        .setSubject("Welcome to Acme, {{ first_name }}")
        .setHtml("<h1>Welcome, {{ first_name }}</h1>")
        .build()
);
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

var template = emailit.Templates.Create(new TemplateCreateOptions {
    Name = "Welcome email",
    Alias = "welcome-email",
    Subject = "Welcome to Acme, {{ first_name }}",
    Html = "<h1>Welcome, {{ first_name }}</h1>"
});
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

$template = Emailit::templates()->create([
    'name' => 'Welcome email',
    'alias' => 'welcome-email',
    'subject' => 'Welcome to Acme, {{ first_name }}',
    'html' => '<h1>Welcome, {{ first_name }}</h1>'
]);
```

**cURL**

```bash
curl https://api.emailit.com/v2/templates \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome email",
    "alias": "welcome-email",
    "subject": "Welcome to Acme, {{ first_name }}",
    "html": "<h1>Welcome, {{ first_name }}</h1>"
  }'
```

**201**

```json
{
  "data": {
    "id": "tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
    "name": "Welcome email",
    "alias": "welcome-email",
    "from": null,
    "subject": "Welcome to Acme, {{ first_name }}",
    "reply_to": null,
    "html": "<h1>Welcome, {{ first_name }}</h1>",
    "text": null,
    "source": null,
    "editor": "html",
    "published_at": "2026-09-30T10:30:00.482119Z",
    "preview_url": null,
    "created_at": "2026-09-30T10:30:00.482119Z",
    "updated_at": "2026-09-30T10:30:00.482119Z"
  },
  "message": "Template was successfully created."
}
```

**400**

```json
{
  "message": "Validation failed",
  "errors": {
    "alias": ["Alias must contain only lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-)"]
  }
}
```

---
Source: https://emailit.com/docs/api-reference/templates/create/

## Retrieve a template — GET /templates/{id}

> Retrieve one template version by ID with its full content, plus a summary of every other version that shares its alias.

# Retrieve a template

Returns one template version, including its content, and lists the other versions of the same alias in `versions`. Templates are looked up by ID only, not by alias. Requires an API key with `full` scope.

`GET /templates/:id`

## Path parameters

- `id` (string, required): Template ID, for example `tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a`.

## Returns

Returns `200 OK` with the template in `data`. Besides the template fields, the response has a `versions` array with the `id`, `name`, `published_at`, `created_at` and `updated_at` of every other version that shares the alias, newest first. The published version is the one with a non-null `published_at`.

Returns `404` with `message: "Template not found"` if the ID doesn't exist in your workspace.

**Request** `GET /templates/{id}`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

const template = await emailit.templates.get('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

template = client.templates.get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$template = $emailit->templates()->get('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

template = client.templates.get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

template, err := client.Templates.Get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

let template = emailit.templates.get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a").await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

EmailitObject template = emailit.templates().get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a");
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

var template = emailit.Templates.Get("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a");
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

$template = Emailit::templates()->get('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**cURL**

```bash
curl https://api.emailit.com/v2/templates/tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a \
  -H "Authorization: Bearer your_api_key"
```

**200**

```json
{
  "data": {
    "id": "tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
    "name": "Welcome email",
    "alias": "welcome-email",
    "from": "Acme <hello@acme.com>",
    "subject": "Welcome to Acme, {{ first_name }}",
    "reply_to": ["support@acme.com"],
    "html": "<h1>Welcome, {{ first_name }}</h1>",
    "text": "Welcome, {{ first_name }}",
    "source": null,
    "editor": "html",
    "published_at": "2026-09-30T10:30:00.482119Z",
    "preview_url": null,
    "created_at": "2026-09-28T08:12:45.103882Z",
    "updated_at": "2026-09-30T10:30:00.482119Z",
    "versions": [
      {
        "id": "tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f",
        "name": "Welcome email (October)",
        "published_at": null,
        "created_at": "2026-09-30T14:02:11.550731Z",
        "updated_at": "2026-09-30T14:02:11.550731Z"
      }
    ]
  }
}
```

**404**

```json
{
  "message": "Template not found"
}
```

---
Source: https://emailit.com/docs/api-reference/templates/get/

## Update a template — POST /templates/{id}

> Update the name, alias, sender, subject or content of a template version. Updating never publishes or unpublishes it.

# Update a template

Updates one template version. Send only the fields you want to change. The version keeps its publish state: a published version stays published and a draft stays a draft. Requires an API key with `full` scope.

`POST /templates/:id`

## Path parameters

- `id` (string, required): Template ID, for example `tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a`.

## Request body

- `name` (string): Template name. Up to 191 characters.

- `alias` (string): New alias. Up to 191 characters; lowercase letters, numbers, underscores and hyphens only. It can't be an alias that another template already uses.

- `from` (string): Default sender, for example `Acme <hello@acme.com>`. Up to 191 characters. Send an empty string to clear it.

- `subject` (string): Default subject line. Up to 191 characters. Send an empty string to clear it.

- `reply_to` (string | string[]): Reply-to address or array of addresses. Send an empty string to clear it.

- `html` (string): HTML body.

- `text` (string): Plain-text body.

- `source` (string): Editor source document, for example Dragit JSON. For an MJML template, the full MJML: Emailit validates it and recompiles `html`, and any `html` you send is ignored.

- `editor` (string): `html`, `text`, `dragit` or `tiptap`. `mjml` is in alpha and open to the Emailit team only; changing an MJML template's content without MJML access returns `403` with `error: "mjml_alpha"`. Renaming or publishing it works for everyone. See [MJML editors and API](/docs/templates/mjml/).

## Returns

Returns `200 OK` with the updated template in `data` and a confirmation `message`. Emailit also sends a [`template.updated`](/docs/webhooks/events/template/updated/) webhook event.

Returns `400` with `message: "Validation failed"` and an `errors` object when a value is invalid, for example `"Alias already exists"`. Values longer than 191 characters or an unknown `editor` return the standard `400` validation error. Returns `404` if the template doesn't exist.

To make this version the one used for sending, call [Publish a template](/docs/api-reference/templates/publish/).

**Request** `POST /templates/{id}`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

const template = await emailit.templates.update('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a', {
  subject: 'Welcome aboard, {{ first_name }}'
});
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

template = client.templates.update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a", {
    "subject": "Welcome aboard, {{ first_name }}"
})
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$template = $emailit->templates()->update('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a', [
    'subject' => 'Welcome aboard, {{ first_name }}'
]);
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

template = client.templates.update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a", subject: "Welcome aboard, {{ first_name }}")
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

template, err := client.Templates.Update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a", &emailit.UpdateTemplateRequest{
    Subject: "Welcome aboard, {{ first_name }}",
})
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

let template = emailit.templates.update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
    emailit::types::UpdateTemplateParams {
        subject: Some("Welcome aboard, {{ first_name }}".into()),
        ..Default::default()
    }
).await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

EmailitObject template = emailit.templates().update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
    TemplateUpdateParams.builder()
        .setSubject("Welcome aboard, {{ first_name }}")
        .build()
);
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

var template = emailit.Templates.Update("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a", new TemplateUpdateOptions {
    Subject = "Welcome aboard, {{ first_name }}"
});
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

$template = Emailit::templates()->update('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a', [
    'subject' => 'Welcome aboard, {{ first_name }}'
]);
```

**cURL**

```bash
curl -X POST https://api.emailit.com/v2/templates/tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"subject": "Welcome aboard, {{ first_name }}"}'
```

**200**

```json
{
  "data": {
    "id": "tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
    "name": "Welcome email",
    "alias": "welcome-email",
    "from": "Acme <hello@acme.com>",
    "subject": "Welcome aboard, {{ first_name }}",
    "reply_to": ["support@acme.com"],
    "html": "<h1>Welcome, {{ first_name }}</h1>",
    "text": "Welcome, {{ first_name }}",
    "source": null,
    "editor": "html",
    "published_at": "2026-09-30T10:30:00.482119Z",
    "preview_url": null,
    "created_at": "2026-09-28T08:12:45.103882Z",
    "updated_at": "2026-10-01T09:15:27.640000Z"
  },
  "message": "Template was successfully updated."
}
```

**400**

```json
{
  "message": "Validation failed",
  "errors": {
    "alias": ["Alias already exists"]
  }
}
```

**404**

```json
{
  "message": "Template not found"
}
```

---
Source: https://emailit.com/docs/api-reference/templates/update/

## List templates — GET /templates

> List the published version of each template in your workspace, with filters, sorting and page-based pagination.

# List templates

Returns the published version of each template, newest first. Unpublished versions aren't listed; [retrieve a template](/docs/api-reference/templates/get/) to see all versions of its alias. Requires an API key with `full` scope.

`GET /templates`

## Query parameters

- `page` (integer): Page number, starting at `1`. Default `1`.

- `per_page` (integer): Templates per page, from `1` to `100`. Default `25`.

- `include_content` (boolean): Set to `true` to include `html`, `text` and `source` on each template. Omitted by default to keep responses small.

- `filter[name]` (string): Case-insensitive partial match on the template name or alias.

- `filter[alias]` (string): Exact alias.

- `filter[editor]` (string): Editor: `html`, `text`, `dragit`, `tiptap` or `mjml` ([alpha](/docs/templates/mjml/)).

- `match` (string): `all` (default) requires every `key.condition` filter to match. `or` matches any of them. See [Filtering](/docs/api-reference/filtering/).

- `sort` (string): Sort key: `name`, `alias`, `created_at` (default), `updated_at` or `published_at`.

- `order` (string): Sort direction: `asc` or `desc` (default).

## Filters

Filter and sort keys: see [Filtering](https://emailit.com/docs/api-reference/filtering/).

On this endpoint, `order` only accepts `asc` or `desc`. Pass the sort key in `sort`, for example `sort=name&order=asc`.

## Returns

Returns `200 OK` with the templates in `data` and the pagination fields `total_records`, `per_page`, `current_page` and `total_pages`. Each template includes `total_versions`, the number of versions that share its alias.

**Request** `GET /templates`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

const templates = await emailit.templates.list();
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

templates = client.templates.list()
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$templates = $emailit->templates()->list();
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

templates = client.templates.list
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

templates, err := client.Templates.List(nil)
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

let templates = emailit.templates.list(None).await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

EmailitObject templates = emailit.templates().list();
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

var templates = emailit.Templates.List();
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

$templates = Emailit::templates()->list();
```

**cURL**

```bash
curl https://api.emailit.com/v2/templates \
  -H "Authorization: Bearer your_api_key"
```

**200**

```json
{
  "data": [
    {
      "id": "tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a",
      "name": "Welcome email",
      "alias": "welcome-email",
      "from": "Acme <hello@acme.com>",
      "subject": "Welcome to Acme, {{ first_name }}",
      "reply_to": ["support@acme.com"],
      "editor": "html",
      "published_at": "2026-09-30T10:30:00.482119Z",
      "preview_url": null,
      "total_versions": 3,
      "created_at": "2026-09-28T08:12:45.103882Z",
      "updated_at": "2026-09-30T10:30:00.482119Z"
    }
  ],
  "total_records": 1,
  "per_page": 25,
  "current_page": 1,
  "total_pages": 1
}
```

**401**

```json
{
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "Invalid API key"
}
```

---
Source: https://emailit.com/docs/api-reference/templates/list/

## Publish a template — POST /templates/{id}/publish

> Publish a template version so sends that use its alias pick it up. Every other version of the alias is unpublished at the same time.

# Publish a template

Publishes a template version and unpublishes every other version with the same alias, in one transaction. Use it to roll out a new draft or to roll back to an earlier version. Requires an API key with `full` scope.

`POST /templates/:id/publish`

## Path parameters

- `id` (string, required): ID of the version to publish, for example `tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f`.

## Request body

No body. Publishing an already published version sets a new `published_at`.

## Returns

Returns `200 OK` with the published template in `data` and a confirmation `message`. Returns `404` if the template doesn't exist.

Emailit sends a [`template.updated`](/docs/webhooks/events/template/updated/) webhook event for the version you published and one for each version that was unpublished.

**Request** `POST /templates/{id}/publish`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

const template = await emailit.templates.publish('tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f');
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

template = client.templates.publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f")
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$template = $emailit->templates()->publish('tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f');
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

template = client.templates.publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f")
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

template, err := client.Templates.Publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f")
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

let template = emailit.templates.publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f").await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

EmailitObject template = emailit.templates().publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f");
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

var template = emailit.Templates.Publish("tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f");
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

$template = Emailit::templates()->publish('tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f');
```

**cURL**

```bash
curl -X POST https://api.emailit.com/v2/templates/tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f/publish \
  -H "Authorization: Bearer your_api_key"
```

**200**

```json
{
  "data": {
    "id": "tem_2xKyB4qLm7RtV9sNd3HwEa6uC1f",
    "name": "Welcome email (October)",
    "alias": "welcome-email",
    "from": "Acme <hello@acme.com>",
    "subject": "Welcome to Acme, {{ first_name }}",
    "reply_to": ["support@acme.com"],
    "html": "<h1>Welcome, {{ first_name }}</h1><p>Here is your October guide.</p>",
    "text": "Welcome, {{ first_name }}. Here is your October guide.",
    "source": null,
    "editor": "html",
    "published_at": "2026-10-01T09:20:04.118502Z",
    "preview_url": null,
    "created_at": "2026-09-30T14:02:11.550731Z",
    "updated_at": "2026-10-01T09:20:04.118000Z"
  },
  "message": "Template was successfully published."
}
```

**404**

```json
{
  "message": "Template not found"
}
```

---
Source: https://emailit.com/docs/api-reference/templates/publish/

## Delete a template — DELETE /templates/{id}

> Permanently delete one template version. Deleting the published version leaves its alias without a published template.

# Delete a template

Permanently deletes one template version. Other versions of the same alias are kept. Requires an API key with `full` scope.

`DELETE /templates/:id`

## Path parameters

- `id` (string, required): Template ID, for example `tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a`.

## Returns

Returns `200 OK` with `data: null` and a confirmation `message`. Emailit sends a [`template.deleted`](/docs/webhooks/events/template/deleted/) webhook event with the deleted version. Returns `404` if the template doesn't exist.

If you delete the published version, no version of that alias is published until you [publish another one](/docs/api-reference/templates/publish/), and sending with that alias fails. Deleting a draft doesn't affect the published version. You can't undo a delete.

**Request** `DELETE /templates/{id}`

**Node.js**

```javascript
import { Emailit } from '@emailit/node';
const emailit = new Emailit('your_api_key');

await emailit.templates.delete('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**Python**

```python
from emailit import EmailitClient
client = EmailitClient("your_api_key")

client.templates.delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**PHP**

```php
$emailit = Emailit::client('your_api_key');

$emailit->templates()->delete('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**Ruby**

```ruby
require "emailit"
client = Emailit::EmailitClient.new("your_api_key")

client.templates.delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**Go**

```go
import "github.com/emailit/emailit-go/v2"
client := emailit.NewClient("your_api_key")

err := client.Templates.Delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a")
```

**Rust**

```rust
use emailit::Emailit;
let emailit = Emailit::new("your_api_key");

emailit.templates.delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a").await?;
```

**Java**

```java
import com.emailit.*;
import com.emailit.params.*;
EmailitClient emailit = new EmailitClient("your_api_key");

emailit.templates().delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a");
```

**.NET**

```csharp
using Emailit;
var emailit = new EmailitClient("your_api_key");

emailit.Templates.Delete("tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a");
```

**Laravel**

```php
use Emailit\Laravel\Facades\Emailit;

Emailit::templates()->delete('tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a');
```

**cURL**

```bash
curl -X DELETE https://api.emailit.com/v2/templates/tem_2xKx7M2c9wQe3kHhJ8sVtY1pZ0a \
  -H "Authorization: Bearer your_api_key"
```

**200**

```json
{
  "data": null,
  "message": "Template was successfully deleted."
}
```

**404**

```json
{
  "message": "Template not found"
}
```

---
Source: https://emailit.com/docs/api-reference/templates/delete/
