> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lettr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> List, get, create, update, and delete Lettr-managed email templates using the client.templates resource in the Node.js SDK.

The `client.templates` resource manages Lettr-managed templates. To *send* a template, see [Sending Emails → Send with a Template](https://docs.lettr.com/quickstart/nodejs/sending-emails.md#send-with-a-template).

## List Templates

```typescript theme={null}
const { data, error } = await client.templates.list({ project_id: 123, per_page: 20 });

if (!error) {
  for (const template of data.templates) {
    console.log(template.name, template.slug);
  }
}
```

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/list-templates.md)
>
> GET /templates

## Get a Template

```typescript theme={null}
const { data, error } = await client.templates.get("welcome-email");
// with a specific project:
await client.templates.get("welcome-email", 123);

if (!error) {
  console.log(data.html);
  console.log(data.active_version);
}
```

## Create a Template

Provide `html` **or** `json` (the TOPOL.io editor format), not both:

```typescript theme={null}
const { data, error } = await client.templates.create({
  name: "My Template",
  html: "<html>...</html>",
  project_id: 123,          // optional
  folder_id: 5,             // optional
  purpose: "campaign",      // optional; "transactional" by default
});

if (!error) {
  console.log(data.id, data.slug, data.active_version);
}
```

> [!WARNING]
>
> **`purpose` is set once and cannot be changed.** Omit it and you get a transactional template, which a [campaign](https://docs.lettr.com/learn/campaigns/introduction.md) cannot use — and `purpose` is not accepted by the update endpoint, so the only remedy is to copy the template in the app. If the content is going to an audience, set it now. See [Transactional vs. Marketing Templates](https://docs.lettr.com/learn/templates/projects.md#transactional-vs-marketing-templates).

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/create-template.md)
>
> POST /templates

## Update & Delete

```typescript theme={null}
await client.templates.update("my-template", { name: "Renamed" });

await client.templates.delete("my-template");
await client.templates.delete("my-template", 123); // within a project
```

## Get Merge Tags

Retrieve the variables a template expects — useful for validating data before sending:

```typescript theme={null}
const { data, error } = await client.templates.getMergeTags("welcome-email", {
  project_id: 123, // optional
  version: 2,      // optional
});

if (!error) {
  for (const tag of data.merge_tags) {
    console.log(tag.key, tag.required, tag.type);
  }
}
```

> [card] [API Reference](https://docs.lettr.com/api-reference/templates/get-merge-tags.md)
>
> GET /templates/{slug}/merge-tags

## What's Next

> [card] [Template Language](https://docs.lettr.com/learn/templates/template-language.md)
>
> Merge tag syntax, conditionals, loops

> [card] [lettr-kit CLI](https://docs.lettr.com/quickstart/nodejs/introduction.md)
>
> Pull and sync templates locally


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.