---
title: "Create a new template"
method: POST
path: "/templates"
tags: ["Templates"]
---

# Create a new template

`POST /templates`

Create a new email template from raw HTML or from an MJML definition. Send exactly one of `html` and `mjml`. A template created from an MJML definition is compiled to HTML by Ecomail and stays editable in the drag-and-drop editor.

## Request body

- object
  - `name` string, required — Template name.
  - `html` string — Template HTML content. Required when `mjml` is not sent. Do not combine with `mjml`.
  - `mjml` object — MJML definition of the template, in the same JSON format the Ecomail editor uses. Required when `html` is not sent. Each node has a `tagName` (an MJML component such as `mj-section`, `mj-column`, `mj-text`, `mj-image`, or `mj-button`), optional `attributes`, and either `children` or `content`.
    - `tagName` string
    - `attributes` object
    - `children` object[], required

## Response `200`

OK

- object
  - `id` integer
  - `name` string
  - `html` string

## Other responses

- `422` — The MJML definition could not be rendered to HTML.

---

[API](https://skmtc.dev/ecomail/apis/ecomail-api.md) · [All operations](https://skmtc.dev/ecomail/apis/ecomail-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/ecomail/ecomail-api/revisions/31b5789931fe/schema)
