テンプレート:ルート

Run Commands

テンプレートへの唯一の入り口です。1リクエストで1〜10個のコマンドを送り、コマンドごとに1つの結果を受け取ります。

POSThttps://g.sendcorex.com/v1/template

Domains、Senders、Contactsと同じエンベロープです。この下のページで各コマンドを説明しています。

エラーはコマンドごとに報告されます。1つのコマンドが失敗してもほかは止まらず、HTTPステータスは200のままです。

ボディパラメーター

  • commandsobject[]必須

    1〜10個のコマンドを順番に実行します。ボディ全体で最大1 MBです。

  • commands[].commandstring必須

    list_templates、get_template、render_template、create_template、update_template、delete_template、list_template_versions、restore_template_versionのいずれか。

  • commands[].argsobject任意

    コマンドの引数。どの値も、前のコマンドの結果への$refにできます。

  • commands[].idstring任意

    結果につける独自の識別子。デフォルトはインデックス("0"、"1"…)。$refを使う場合は必須。

クイックスタート

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "list_templates",
        id: "all"
      },
      {
        command: "render_template",
        id: "preview",
        args: {
          template_id: "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
          variables: {
            first_name: "Ana",
            plan: "Pro"
          }
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

for (const result of response.data.results) {
  if (result.type !== 'SUCCESS') console.error(result.id, result.code, result.message);
  else console.log(result.id, result.data);
}

レスポンス

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "list_templates",
      "id": "all",
      "type": "SUCCESS",
      "took_ms": 6,
      "data": {
        "templates": [
          {
            "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"
          },
          {
            "template_id": "unlayer_1284",
            "type": "unlayer",
            "name": "October newsletter",
            "reference": "B3VN8QK1ZT",
            "preview": "https://res.cloudinary.com/dmg04ffuy/image/upload/v1760000000/previews/oct_newsletter.png",
            "has_html": true,
            "html_size": 48211,
            "editable": false,
            "created_at": "2026-10-01T09:12:00.000Z",
            "updated_at": "2026-10-18T16:40:22.118Z"
          }
        ]
      }
    },
    {
      "command": "render_template",
      "id": "preview",
      "type": "SUCCESS",
      "took_ms": 3,
      "data": {
        "template_id": "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
        "subject": "Welcome to Acme, Ana",
        "html": "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, Ana!</h1><p>Your Pro plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
        "text": "Welcome, Ana! Your Pro plan is ready. Get started: https://acme.com/start",
        "missing_variables": []
      }
    }
  ]
}

レスポンスの項目

  • type

    リクエスト自体が受け付けられた場合は常にSUCCESS。

  • results[].command

    この結果を生成したコマンド。

  • results[].id

    送ったid、またはコマンドのインデックス。

  • results[].type

    SUCCESSまたはERROR。

  • results[].took_ms

    サーバー内でコマンドにかかった時間。

  • results[].data

    コマンドの出力。typeがSUCCESSの場合のみ。

  • results[].code / message

    エラー。typeがERRORの場合のみ。

認証

ダッシュボードのDevelopers → API Keysで作成したAPI keyを、コマンドに必要なスコープ付きで使います。

  • Authorization

    Authorization: <api key>またはAuthorization: Bearer <api key>を送ります。

  • template:read

    list_templates、get_template、render_template、list_template_versions。

  • template:create

    create_template。

  • template:update

    update_templateとrestore_template_version。

  • template:delete

    delete_template。

  • メールボックスのトークン

    Webmailのトークンはここでは使えず、WRONG_CREDENTIAL_TYPEで拒否されます。

  • 許可するIP

    キーにIP許可リストがある場合、ほかのIPからのリクエストには403 IP_NOT_ALLOWEDが返ります。

$refでつなぐ

テンプレートを作成し、同じリクエストでレンダリングして結果を確認します。

create_template → render_template

{
  "commands": [
    {
      "command": "create_template",
      "id": "new",
      "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>"
      }
    },
    {
      "command": "render_template",
      "args": {
        "template_id": {
          "$ref": "new",
          "path": "template_id"
        },
        "variables": {
          "first_name": "Ana",
          "plan": "Pro"
        }
      }
    }
  ]
}

レート制限とキャッシュ

  • 毎秒15リクエスト

    IP + API keyごと。超えるとHTTP 429とRetry-Afterヘッダー。

  • 同時15件

    IP + API keyごとに、同時に処理されるリクエストは最大15件。

  • コマンドごと、アカウントごと

    create_template 30回/分 · update_template 60回/分 · restore_template_version 20回/分 · delete_template 30回/分。超えるとそのコマンドはRATE_LIMITEDを返します。

  • 読み取りキャッシュ:1.5秒

    1.5秒以内の同じ読み取りは同じ結果を返します。このルートで書き込みがあるとリセットされます。

エラー

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

  • 400INVALID_JSON

    ボディが{"commands":[...]}ではないか、1 MBを超えています。

  • 400INVALID_ARGS

    リクエストにコマンドがないか、10個を超えています。

  • 401MISSING_AUTH_HEADER

    Authorizationヘッダーが送られていません。

  • 401INVALID_API_KEY

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

  • 401API_KEY_EXPIRED

    API keyがダッシュボードで設定した有効期限を過ぎています。

  • 401WRONG_CREDENTIAL_TYPE

    メールボックスのtokenが送られました。Templates APIにはダッシュボードのAPI keyが必要です。

  • 403IP_NOT_ALLOWED

    キーの許可IPにないIPからのリクエストです。

  • 403ACCOUNT_BLOCKED

    アカウントがブロックされています。

  • 403MISSING_SCOPE

    キーに`template:*`のscopeがないため、どのコマンドも実行できません。

  • 429RATE_LIMITED

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

  • 503AUTH_UNAVAILABLE

    認証が一時的に利用できません。もう一度お試しください。

  • CMDUNKNOWN_COMMAND

    そのコマンド名は存在しません。

  • CMDINTERNAL

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