---
title: "Create a snippet"
method: POST
path: "/api/snippets"
tags: ["Templates"]
---

# Create a snippet

`POST /api/snippets`

## Request

- Base URL: `https://api.sendly.now`
- URL: `https://api.sendly.now/api/snippets`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `better-auth.session_token`
  - OAuth 2 (authorization code, authorization URL `https://app.sendly.now/api/auth/oauth2/authorize`, token URL `https://app.sendly.now/api/auth/oauth2/token`, scopes: `templates:write`)

`name` is the literal identifier templates include with `{{> name}}`: it must start with a letter and contain only letters, digits, hyphen or underscore, and it is unique within the project.

Requires the `templates:write` scope — Create, edit, and delete your email templates.

## Request body

- CreateSnippet: Body for POST /api/snippets.
  - `body` string, required
  - `description` string, nullable
  - `name` string, required

## Response `201`

Snippet created

- object
  - `data` Snippet, required: A reusable fragment of template markup.
    - `body` string, required: Template markup. Values it interpolates are escaped like any other.
    - `createdAt` string, date-time, required: ISO 8601 datetime string
    - `description` string, nullable
    - `id` string, uuid, required
    - `name` string, required: The literal identifier a template includes with `{{> name}}`.
    - `projectId` string, uuid, required
    - `updatedAt` string, date-time, required: ISO 8601 datetime string
  - `success` true, required

## Other responses

- `400`: Validation error
- `401`: Unauthorized — missing or invalid auth
- `403`: Forbidden — insufficient permissions or project disabled
- `409`: A snippet with that name already exists in this project
- `422`: Validation failed — request body or query parameters did not match the schema
- `429`: Rate limit or billing limit exceeded
- `500`: Internal server error

---

[API](https://skmtc.dev/sendly/apis/sendly-api.md) · [All operations](https://skmtc.dev/sendly/apis/sendly-api/llms.txt) · [OpenAPI document](https://skmtc.dev/sendly/apis/sendly-api/revisions/ce7cfb7f7c7e?raw)
