テンプレート:編集

Create Template

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

POSThttps://g.sendcorex.com/v1/templatecommand: create_template

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

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

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

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

引数

  • namestring必須

    最大255文字、HTMLは不可。

    例: "Welcome email"

  • htmlstring必須

    完全な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>"

  • textstring任意

    プレーンテキスト版。

    例: "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"

  • subjectstring任意

    既定の件名。変数を含められます。

    例: "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でコマンドの結果内に返ります。

  • 401INVALID_API_KEY

    API keyが存在しないか、取り消されたか、ダッシュボードで無効化されています。

  • 429RATE_LIMITED

    同じIP + API keyで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。

  • CMDMISSING_SCOPE

    API keyにこのコマンドに必要なスコープがありません。

  • CMDINVALID_ARGS

    引数が無効です:形式が正しくない`template_id`、`name`や`html`がない、255文字を超える名前、RFC 3339でない`version_at`…

  • CMDUNSAFE_HTML

    htmlにメールでは扱えないものが含まれています:`<script>`、`<iframe>`、フォーム、`on*=`ハンドラー、`javascript:`のリンクなど。メッセージに削除すべきものが正確に書かれています。

  • CMDTEMPLATE_TOO_LARGE

    htmlが512 KBを超えています。画像は埋め込まずにホストしてリンクしてください。

  • CMDRATE_LIMITED

    直近1分間にアカウントがこのコマンドを呼びすぎました。1分待ってください。

  • CMDINTERNAL

    サーバーエラー。詳細はサーバーのログにのみ記録されます。