---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/ja/api-reference/templates/editing/create-template

テンプレート：編集

# Create Template

自分のhtmlをテンプレートとして保存します：MJML、React Email、デザイナー、どんなツールで作ったものでも構いません。ダッシュボードでエディターのテンプレートと並んで表示されます。

POST `https://g.sendcorex.com/v1/template` command: create_template

API keyに`template:create`スコープが必要です。

1アカウントにつき1分あたり最大30回。超えるとコマンドは`RATE_LIMITED`を返します。

htmlは保存時に、送信時と同じルールでチェックされます：メールが拒否されたときではなく、その場で問題がわかります。

最初のバージョンも一緒に保存されます。List Template Versionsを参照してください。

## 引数

- `name` string 必須
最大255文字、HTMLは不可。
例： `"Welcome email"`
- `html` string 必須
完全なhtml（最大512 KB）。メールごとに変わる部分には`{{variables}}`を使います。
例： `"<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>"`
- `text` string 任意
プレーンテキスト版。
例： `"Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"`
- `subject` string 任意
既定の件名。変数を含められます。
例： `"Welcome to Acme, {{first_name}}"`

## クイックスタート

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "create_template",
        args: {
          name: "Welcome email",
          subject: "Welcome to Acme, {{first_name}}",
          html: "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
          text: "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);
```

## レスポンス

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "create_template",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 9,
      "data": {
        "template_id": "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
        "type": "html",
        "name": "Welcome email",
        "reference": "K7Q2M9XR4T",
        "preview": null,
        "has_html": true,
        "html_size": 248,
        "editable": true,
        "created_at": "2026-10-21T04:02:11.310Z",
        "updated_at": "2026-10-21T04:15:40.902Z",
        "subject": "Welcome to Acme, {{first_name}}",
        "html": "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
        "text": "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"
      }
    }
  ]
}
```

### レスポンスの項目

- `template_id`
テンプレートのid：`html_<uuid>`、`unlayer_<number>`、`custom_<uuid>`。ほかのすべてのコマンドで使います。
- `type`
`html`（APIで送った自分のもの）、`unlayer`（ドラッグ＆ドロップのエディターで作成）、`custom`（Sendcorexのエディターで作成）。
- `name`
付けた名前。
- `reference`
ダッシュボードでもテンプレートを識別できる短いコード。
- `preview`
エディターのテンプレートの画像。htmlテンプレートと、まだ保存されていないエディターのテンプレートでは`null`。
- `has_html`
作成されたが一度も保存されていないエディターのテンプレートでは`false`。まだレンダリングも送信もできません。
- `html_size`
htmlのサイズ（バイト）。
- `editable`
htmlテンプレートでは`true`：ここで更新、復元、削除ができます。エディターのテンプレートはAPIでは読み取り専用です。
- `created_at / updated_at`
ISO 8601、UTC。
- `subject`
既定の件名、または`null`。変数を含められます。
- `html`
html。一度も保存されていないエディターのテンプレートでは`null`。
- `text`
プレーンテキスト版、または`null`。付けて送ってください：テキスト版のあるメールを好むクライアントやフィルターがあります。

## 変数

- `構文`
subject、html、textのどこにでも`{{name}}`と書けます。波かっこ内の空白も使えます：`{{ name }}`。名前には英字、数字、`_`、`.`、`-`を使います。
- `htmlの中`
値はHTMLエスケープされます：`<`や`&`を含む値でも、レイアウトを壊したりマークアップを挿入したりすることはありません。
- `subjectとtextの中`
値はそのまま入ります。
- `足りない値`
送らなかった変数は`{{name}}`のまま残り、`missing_variables`に列挙されます。送信前に確認してください。

## htmlに含められるもの

- `使用可能`
メールクライアントが表示できるものすべて：テーブル、インラインスタイル、`<style>`ブロック、URLで指定した画像、リンク。
- `拒否`
`<script>`、`<iframe>`、`<form>`、`<input>`、`<button>`、`<embed>`、`<object>`、インラインの`<svg>`、`<base>`、`on*=`ハンドラー、`javascript:`のURL。ボタンの代わりにスタイルを付けた`<a>`を使ってください。
- `画像`
画像はホストしてリンクしてください。base64で埋め込んだ画像はhtmlを重くし、約100 KBを超えるとGmailで切り詰められることがよくあります。

## エラー

HTTPレベルのエラーは`type`、`code`、`message`を返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

- 401`INVALID_API_KEY`
API keyが存在しないか、取り消されたか、ダッシュボードで無効化されています。
- 429`RATE_LIMITED`
同じIP + API keyで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。
- CMD`MISSING_SCOPE`
API keyにこのコマンドに必要なスコープがありません。
- CMD`INVALID_ARGS`
引数が無効です：形式が正しくない`template_id`、`name`や`html`がない、255文字を超える名前、RFC 3339でない`version_at`…
- CMD`UNSAFE_HTML`
htmlにメールでは扱えないものが含まれています：`<script>`、`<iframe>`、フォーム、`on*=`ハンドラー、`javascript:`のリンクなど。メッセージに削除すべきものが正確に書かれています。
- CMD`TEMPLATE_TOO_LARGE`
htmlが512 KBを超えています。画像は埋め込まずにホストしてリンクしてください。
- CMD`RATE_LIMITED`
直近1分間にアカウントがこのコマンドを呼びすぎました。1分待ってください。
- CMD`INTERNAL`
サーバーエラー。詳細はサーバーのログにのみ記録されます。
