> ## 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.

# Tenant Templates API

> Read, write, publish, and version a tenant's templates with the endpoints Courier Create uses, with your API key on the server or a tenant-scoped JWT.

Courier Create reads and writes through these endpoints, so anything the editor does you can script.

```bash theme={null}
curl --request GET \
  --url https://api.courier.com/tenants/acme-corp/templates \
  --header "Authorization: Bearer $COURIER_API_KEY"
```

## Authentication

Two credentials reach these endpoints, and which one you use depends on where the code runs.

Your server uses the API key, as above. The browser uses a JWT scoped to one Tenant, which
is the same token `TemplateProvider` takes. Issue it with
[`POST /auth/issue-token`](https://www.courier.com/docs/api-reference/authentication/create-a-jwt)
and scope it as the
[Courier Create overview](https://www.courier.com/docs/design/embedded-designer/overview.md#scopes) lists.

**Never send the API key from a browser.** It carries the whole workspace, not one Tenant,
so a customer holding it can read and write every other customer's Templates.

## Endpoints

| Operation | Method and path |
| - | - |
| List a Tenant's Templates | [`GET /tenants/{tenant_id}/templates`](https://www.courier.com/docs/api-reference/tenant-templates/list-templates-in-tenant) |
| Read one Template | [`GET /tenants/{tenant_id}/templates/{template_id}`](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-in-tenant) |
| Create or replace a draft | [`PUT /tenants/{tenant_id}/templates/{template_id}`](https://www.courier.com/docs/api-reference/tenant-templates/create-or-update-a-tenant-template) |
| Delete a Template | [`DELETE /tenants/{tenant_id}/templates/{template_id}`](https://www.courier.com/docs/api-reference/tenant-templates/delete-a-tenant-template) |
| Publish the draft | [`POST /tenants/{tenant_id}/templates/{template_id}/publish`](https://www.courier.com/docs/api-reference/tenant-templates/publish-a-tenant-template) |
| Read one version | [`GET /tenants/{tenant_id}/templates/{template_id}/versions/{version}`](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-version) |

A `PUT` replaces the draft rather than merging into it, so send the whole document. Reading
first and writing back a modified copy is the safe order.

## Publishing is a separate call

A write leaves a draft. A draft doesn't send, so a customer who edits and closes the tab
has changed nothing a recipient will see. Publishing is what promotes it.

```bash theme={null}
curl --request POST \
  --url https://api.courier.com/tenants/acme-corp/templates/nt_01kx4h2jdafq8bk9aftxak4b40/publish \
  --header "Authorization: Bearer $COURIER_API_KEY"
```

The editor publishes for the customer through its own button, or through
`useTemplateActions` when you hide it. See
[Template editor](https://www.courier.com/docs/design/embedded-designer/template-editor.md#publish-from-your-own-button).

## Versions

Publishing keeps the previous published document, and
[`GET /tenants/{tenant_id}/templates/{template_id}/versions/{version}`](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-version)
reads one back by version. Use it to show a customer what changed, or to restore a document
by writing an older version back with a `PUT`.

## Common responses

| Status | Meaning |
| - | - |
| `200` | The read or write succeeded. |
| `204` | The delete succeeded and returned no body. |
| `400` | The document failed validation. An Elemental document has to be wrapped in a channel element to be stored. |
| `401` | The credential is missing, malformed, or expired. |
| `403` | The credential is valid but its scope doesn't cover this Tenant or this operation. |
| `404` | No Template with that id in this Tenant. |

`401` and `403` separate cleanly. A `401` means fix the token. A `403` means the token works
but was scoped too narrowly, usually a missing `brand` scope or a `tenant` in the scope that
doesn't match the path.

## Tenant Templates aren't workspace Templates

These two live in different places and neither endpoint reaches the other.

| | Tenant Template | Workspace Template |
| - | - | - |
| Belongs to | One Tenant | The workspace |
| Path | `/tenants/{tenant_id}/templates/...` | `/notifications/...` |
| Edited by | Your customer, in Courier Create | Your team, in Design Studio |
| Documented in | This page | [Templates API](https://www.courier.com/docs/design/templates/api.md) |

A Template your customer writes in Courier Create doesn't appear in the workspace Template
list, and a workspace Template isn't editable through these endpoints. Sending to a Tenant
resolves that Tenant's own Template.

## Verify

List the Tenant's Templates, write a draft with a `PUT`, then read it back. Publish it and
read it again. The published document is what a send to that Tenant now resolves.

## FAQ

> [accordion] Why does my edit not reach recipients?
>
> A write leaves a draft. Call the publish endpoint, or publish from the editor, before a
> send resolves the new document.

> [accordion] What separates a 401 from a 403 here?
>
> A `401` means the credential is missing, malformed, or expired. A `403` means the
> credential is valid but too narrowly scoped, usually a missing `brand` scope or a
> `tenant` scope that doesn't match the path.

> [accordion] Do these endpoints reach my workspace Templates?
>
> Tenant Templates and workspace Templates are separate. Workspace Templates live under
> `/notifications` and are documented in the [Templates API](https://www.courier.com/docs/design/templates/api.md).

> [accordion] Can a browser call these endpoints directly?
>
> A browser can call them with a Tenant-scoped JWT. The API key stays on your server,
> because it carries the whole workspace rather than one Tenant.
