เทมเพลต: เส้นทาง
Run Commands
จุดเข้าใช้งานเดียวสำหรับเทมเพลต ส่ง 1 ถึง 10 คำสั่งในคำขอเดียว และได้ผลลัพธ์หนึ่งรายการต่อคำสั่ง
https://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_versioncommands[].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[].ididที่คุณส่ง หรือดัชนีของคำสั่งresults[].typeSUCCESSหรือERRORresults[].took_msเวลาที่คำสั่งใช้ในเซิร์ฟเวอร์
results[].dataผลลัพธ์ของคำสั่ง มีเฉพาะเมื่อ
typeเป็นSUCCESSresults[].code / messageข้อผิดพลาด มีเฉพาะเมื่อ
typeเป็นERROR
การยืนยันตัวตน
ใช้ API key ที่สร้างในแดชบอร์ด ที่ Developers → API Keys พร้อมขอบเขตที่คำสั่งต้องการ
Authorizationส่ง
Authorization: <api key>หรือAuthorization: Bearer <api key>template:readlist_templates,get_template,render_templateและlist_template_versionstemplate:createcreate_templatetemplate:updateupdate_templateและrestore_template_versiontemplate:deletedelete_templateโทเค็นกล่องจดหมายโทเค็น webmail ใช้ที่นี่ไม่ได้ จะถูกปฏิเสธด้วย
WRONG_CREDENTIAL_TYPEIP ที่อนุญาตหากคีย์มีรายการ 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-After15 พร้อมกันคำขอที่ประมวลผลพร้อมกันสูงสุด 15 ต่อ IP + API key
ต่อคำสั่ง ต่อบัญชีcreate_template30/นาที ·update_template60/นาที ·restore_template_version20/นาที ·delete_template30/นาที หากเกิน คำสั่งนั้นจะตอบRATE_LIMITEDแคชการอ่าน: 1.5 วินาทีการอ่านแบบเดียวกันภายใน 1.5 วินาทีได้ผลลัพธ์เดิม การเขียนใด ๆ บนเส้นทางนี้จะล้างค่านี้
ข้อผิดพลาด
ข้อผิดพลาดระดับ HTTP ส่งกลับ type, code และ message ข้อผิดพลาดที่มีเครื่องหมาย CMD จะกลับมาในผลลัพธ์ของคำสั่ง พร้อม HTTP 200
- 400
INVALID_JSONbody ไม่ใช่ {"commands":[...]} หรือใหญ่กว่า 1 MB
- 400
INVALID_ARGSคำขอไม่มีคำสั่งหรือมีมากกว่า 10 คำสั่ง
- 401
MISSING_AUTH_HEADERไม่ได้ส่งเฮดเดอร์ Authorization
- 401
INVALID_API_KEYAPI key ไม่มีอยู่ ถูกเพิกถอน หรือถูกปิดในแดชบอร์ด
- 401
API_KEY_EXPIREDAPI key เลยวันหมดอายุที่ตั้งในแดชบอร์ดแล้ว
- 401
WRONG_CREDENTIAL_TYPEมีการส่ง token ของกล่องจดหมาย Templates API ต้องใช้ API key ของแดชบอร์ด
- 403
IP_NOT_ALLOWEDคำขอมาจาก IP ที่ไม่อยู่ใน IP ที่อนุญาตของคีย์
- 403
ACCOUNT_BLOCKEDบัญชีถูกบล็อก
- 403
MISSING_SCOPEคีย์ไม่มี scope `template:*` จึงไม่มีคำสั่งใดทำงานได้
- 429
RATE_LIMITEDเกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + API key เดียวกัน รอจำนวนวินาทีใน Retry-After
- 503
AUTH_UNAVAILABLEการยืนยันตัวตนใช้งานไม่ได้ชั่วคราว ลองอีกครั้ง
- CMD
UNKNOWN_COMMANDไม่มีชื่อคำสั่งนี้
- CMD
INTERNALข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์