เทมเพลต: เส้นทาง

Run Commands

จุดเข้าใช้งานเดียวสำหรับเทมเพลต ส่ง 1 ถึง 10 คำสั่งในคำขอเดียว และได้ผลลัพธ์หนึ่งรายการต่อคำสั่ง

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

ซองเดียวกับ Domains, Senders และ Contacts หน้าถัดจากนี้อธิบายแต่ละคำสั่ง

ข้อผิดพลาดรายงานต่อคำสั่ง คำสั่งที่ล้มเหลวไม่หยุดคำสั่งอื่น และสถานะ HTTP ยังเป็น 200

พารามิเตอร์ body

  • commandsobject[]จำเป็น

    1 ถึง 10 คำสั่ง ทำงานตามลำดับ body ทั้งหมดมีขนาดได้ถึง 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

การยืนยันตัวตน

ใช้ API key ที่สร้างในแดชบอร์ด ที่ Developers → API Keys พร้อมขอบเขตที่คำสั่งต้องการ

  • 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 พร้อมกัน

    คำขอที่ประมวลผลพร้อมกันสูงสุด 15 ต่อ IP + API key

  • ต่อคำสั่ง ต่อบัญชี

    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

    body ไม่ใช่ {"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

    คีย์ไม่มี scope `template:*` จึงไม่มีคำสั่งใดทำงานได้

  • 429RATE_LIMITED

    เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + API key เดียวกัน รอจำนวนวินาทีใน Retry-After

  • 503AUTH_UNAVAILABLE

    การยืนยันตัวตนใช้งานไม่ได้ชั่วคราว ลองอีกครั้ง

  • CMDUNKNOWN_COMMAND

    ไม่มีชื่อคำสั่งนี้

  • CMDINTERNAL

    ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์