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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Templates

> What a template holds (content, channels, routing, brand, and translations), how drafts and published versions work, and how to send it by ID or alias.

A template defines what a notification says, how it looks, and how it behaves across channels.

You build it once, then send it through email, SMS, push, chat, or in-app. A template is Elemental content plus channel, routing, and brand settings. Build it visually in the designer, or as code through the Templates API.

## Which one to use

A template built in the designer and one managed through the API are the same object, and it is [Elemental](https://www.courier.com/docs/design/elemental/overview.md) content either way. The difference is where your team would rather work.

> [card] [Design a template](https://www.courier.com/docs/design/templates/design-studio.md)
>
> Build it in the visual editor: drag-and-drop blocks, per-channel content, test-data previews, and version history.
>
> Best when PMs, designers, and developers work on content together.

> [card] [Template API](https://www.courier.com/docs/design/templates/api.md)
>
> Manage it as JSON: create, update, and publish from your codebase, review changes in Git, and test payloads in CI.
>
> Best when templates live in code, or you would rather not click through a UI.

## How it works

Beyond content, a template carries the settings that shape a send:

* **Channels** it can go out on
* Reusable **routing**, primary and fallback
* A **Brand** for consistent styling
* **Conditional logic** to show or hide content by data or preference
* **Variables** that personalize each recipient's version
* **Translations** so each recipient gets their language

See [variables & Handlebars](https://www.courier.com/docs/design/templates/variables.md) for the personalization model, [brands](https://www.courier.com/docs/design/brands.md) for styling, and [template translations](https://www.courier.com/docs/design/elemental/locales.md) for languages.

### Draft, publish, and version history

Editing a template updates its **draft**. Publishing snapshots the draft as the active **version**. A normal send renders the published version, so recipients never see an unfinished edit. Version history lets you compare versions side by side and roll back. A message's log records the version it used, so you can trace a rendering change to a publish.

[Go live](https://www.courier.com/docs/guides/go-live.md) covers reviewing a draft before you publish it.

### How a template is performing

Sends, deliveries, opens, clicks, and errors are reported per template, split by channel and provider. [Analytics](https://www.courier.com/docs/monitor/analytics.md) shows them in the Courier app, and [template metrics](https://www.courier.com/docs/monitor/template-metrics.md) returns the same series over the API for your own dashboards.

## Send it by ID or alias

Both paths end the same way. Pass the Template ID and the data its variables need to [`POST /send`](https://www.courier.com/docs/api-reference/send/send-a-message):

```javascript Node.js theme={null}
const { requestId } = await client.send.message({
  message: {
    to: { email: 'sarah@acme-corp.com' },
    template: 'nt_01kx4h2jdafq8bk9aftxak4b40',
    data: { invite_url: 'https://www.acme-corp.com/invite' },
  },
});
```

```python Python theme={null}
response = client.send.message(
    message={
        "to": {"email": "sarah@acme-corp.com"},
        "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
        "data": {"invite_url": "https://www.acme-corp.com/invite"},
    },
)
```

```bash cURL theme={null}
curl -X POST https://api.courier.com/send \
  -H "Authorization: Bearer $COURIER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "to": { "email": "sarah@acme-corp.com" },
      "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
      "data": { "invite_url": "https://www.acme-corp.com/invite" }
    }
  }'
```

```ruby Ruby theme={null}
response = courier.send_.message(
  message: {
    to: { email: "sarah@acme-corp.com" },
    template: "nt_01kx4h2jdafq8bk9aftxak4b40",
    data: { invite_url: "https://www.acme-corp.com/invite" }
  }
)
```

```go Go theme={null}
response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
	Message: courier.SendMessageParamsMessage{
		To: courier.SendMessageParamsMessageToUnion{
			OfUserRecipient: &shared.UserRecipientParam{
				Email: courier.String("sarah@acme-corp.com"),
			},
		},
		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
		Data: map[string]any{
			"invite_url": "https://www.acme-corp.com/invite",
		},
	},
})
```

```java Java theme={null}
SendMessageParams params = SendMessageParams.builder()
    .message(SendMessageParams.Message.builder()
        .to(JsonValue.from(java.util.Map.of("email", "sarah@acme-corp.com")))
        .template("nt_01kx4h2jdafq8bk9aftxak4b40")
        .data(JsonValue.from(java.util.Map.of("invite_url", "https://www.acme-corp.com/invite")))
        .build())
    .build();
client.send().message(params);
```

```php PHP theme={null}
$response = $client->send->message(
  message: [
    'to' => ['email' => 'sarah@acme-corp.com'],
    'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
    'data' => ['invite_url' => 'https://www.acme-corp.com/invite'],
  ],
);
```

```csharp C# theme={null}
SendMessageParams parameters = new()
{
    Message = new()
    {
        To = new UserRecipient { Email = "sarah@acme-corp.com" },
        Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
        Data = new Dictionary<string, JsonElement>()
        {
            { "invite_url", JsonSerializer.SerializeToElement("https://www.acme-corp.com/invite") },
        },
    },
};

await client.Send.Message(parameters);
```

```bash CLI theme={null}
courier send message \
  --api-key "$COURIER_API_KEY" \
  --message '{"to":{"email":"sarah@acme-corp.com"},"template":"nt_01kx4h2jdafq8bk9aftxak4b40","data":{"invite_url":"https://www.acme-corp.com/invite"}}'
```

```text MCP theme={null}
With Courier MCP, send my nt_01kx4h2jdafq8bk9aftxak4b40 template to sarah@acme-corp.com with the invite URL.
```

That `template` field accepts either form:

| Value | Looks like | Where it comes from |
| - | - | - |
| **Template ID** | `nt_01kx4h2jdafq8bk9aftxak4b40` | Generated by Courier, shown in the template's settings |
| **Alias** | `order-confirmation` | A name you assign, in the template's **settings** under **Alias** or with `notification.alias` over the API |

An alias is the readable name your code keeps while the template behind it changes. You assign one in the template's **settings**, under **Alias**, or with `notification.alias` when you create or replace the template over the API. Setting it to `null` clears it, and leaving it out keeps the existing alias. It then sits exactly where the ID sat, and nothing else about the request changes.

Three rules govern them:

* **A template has one alias.** Setting a new one replaces the old one, and sends that still use the old name end `UNMAPPED`.
* **An alias belongs to one template.** Assigning an alias another template holds returns `409`, so clear it there first, by setting that template's alias to `null`.
* **An alias works anywhere the ID works.** Nothing else in the request changes.

Moving an alias to another template switches the content behind a send with no deploy, for every caller at once.

## FAQ

> [accordion] Can I manage a template in code and in the designer?
>
> Both operate on the same template. One team can edit in the designer while another manages it through the API. Coordinate publishes so a draft edit isn't overwritten.

> [accordion] What is the difference between a draft and a published template?
>
> Edits go to the draft. Publishing makes the draft the active version. Normal sends render the published version.

> [accordion] Can I reference a template by a stable name?
>
> Assign an alias and pass it as `template` on the send, so your code references a human-readable name instead of the generated ID.
