> ## 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 with the Lettr Go SDK Templates service.

The `client.Templates` service manages Lettr-managed templates. To *send* a template, set `TemplateSlug` on `SendEmailRequest` — see [Sending Emails](https://docs.lettr.com/quickstart/go/quickstart.md#sending-emails).

```go theme={null}
import lettr "github.com/lettr-com/lettr-go"

client := lettr.NewClient("your-api-key")
```

## List Templates

```go theme={null}
templates, err := client.Templates.List(ctx, &lettr.ListTemplatesParams{
    ProjectID: 5,
    PerPage:   10,
    Page:      1,
})
```

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

## Get a Template

```go theme={null}
template, err := client.Templates.Get(ctx, "welcome-email", nil)

// With a specific project
template, err = client.Templates.Get(ctx, "welcome-email", &lettr.GetTemplateParams{
    ProjectID: 5,
})
```

## Create a Template

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

```go theme={null}
created, err := client.Templates.Create(ctx, &lettr.CreateTemplateRequest{
    Name:    "Welcome Email",
    Html:    "<h1>Hello {{FIRST_NAME}}!</h1>",
    Purpose: lettr.PurposeCampaign, // optional; transactional by default
})
```

> [!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

```go theme={null}
updated, err := client.Templates.Update(ctx, "welcome-email", &lettr.UpdateTemplateRequest{
    Html: "<h1>Updated Hello {{FIRST_NAME}}!</h1>",
})

_, err = client.Templates.Delete(ctx, "welcome-email", nil)
```

## Get Merge Tags

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

```go theme={null}
tags, err := client.Templates.GetMergeTags(ctx, "welcome-email", nil)
for _, tag := range tags.Data.MergeTags {
    fmt.Printf("Tag: %s (required: %v)\n", tag.Key, tag.Required)
}
```

> [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] [Sending Emails](https://docs.lettr.com/quickstart/go/quickstart.md)
>
> Send a template with substitution data


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