---
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/th/api-reference/templates

เทมเพลต

# เทมเพลตของคุณ จากเอดิเตอร์หรือจากโค้ด

อ่านเทมเพลตที่ทีมของคุณสร้างในเอดิเตอร์ของแดชบอร์ด หรือนำ HTML ของคุณเองมาจัดการเหมือนโค้ด: ตัวแปร การตรวจสอบตอนบันทึก และเวอร์ชันที่ย้อนกลับได้

- คำสั่ง JSON
- นำ HTML ของคุณเองมา
- ตัวแปร
- 10 เวอร์ชัน
- ตรวจสอบตอนบันทึก

เริ่มต้น ดูคำสั่ง

POST `https://g.sendcorex.com/v1/template` template:*

## วิธีการทำงาน

สามประเภท หนึ่ง API

แบบลากและวาง (Unlayer) เอดิเตอร์ของ Sendcorex (Custom) และ HTML ของคุณเอง แสดงรายการ อ่าน และเรนเดอร์ได้แบบเดียวกัน

ไม่ผูกกับเอดิเตอร์

สร้างอีเมลด้วย MJML, React Email หรือนักออกแบบ? ส่ง HTML มาได้เลย จะถูกตรวจสอบตอนบันทึกด้วยกฎเดียวกับการส่ง เทมเพลตที่บันทึกได้จึงส่งได้

มีเวอร์ชันให้

ทุกการเปลี่ยนเทมเพลต HTML จะบันทึกเวอร์ชัน การ deploy ที่ผิดพลาดแก้ได้ด้วย Restore Template Version ครั้งเดียว

## เริ่มต้น

ก่อนคำขอแรกต้องมีเพียงคีย์

1. 1
สร้าง API key ที่มี scope ของเทมเพลต
ในแดชบอร์ด เปิด Developers → API Keys แล้วให้คีย์มี template:read รวมถึง template:create, template:update และ template:delete หากใช้จัดการ HTML ของคุณเอง
โทเค็น webmail ใช้ที่นี่ไม่ได้ API นี้ใช้ API key จากแดชบอร์ด
[เปิด API Keys](https://app.sendcorex.com/dashboard/developer)
2. 2
บันทึก HTML ของคุณ
Create Template พร้อมชื่อและ HTML ใช้ {{variables}} สำหรับส่วนที่เปลี่ยนในแต่ละอีเมล
[Create Template](https://docs.sendcorex.com/th/api-reference/templates/editing/create-template)
3. 3
เรนเดอร์แล้วส่ง
Render Template เติมตัวแปรและบอกว่าตัวไหนขาด ส่งผลลัพธ์ต่อให้ Send Email
[เรนเดอร์เทมเพลต](https://docs.sendcorex.com/th/api-reference/templates/templates/render-template) [ส่งอีเมล](https://docs.sendcorex.com/th/api-reference/email/send)

## เทมเพลต

Get Template, Create Template และ Update Template ส่งกลับรูปแบบนี้ List Templates ส่งกลับโดยไม่มี subject, html และ text

```
{
  "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`

html_<uuid>, unlayer_<number> หรือ custom_<uuid> คำนำหน้าคือประเภท

`editable`

true สำหรับ HTML ของคุณเอง เทมเพลตจากเอดิเตอร์อ่านได้อย่างเดียวผ่าน API

`{{variables}}`

placeholder ใน subject, html และ text ที่ Render Template เติมให้

`preview`

ภาพตัวอย่างของเทมเพลตจากเอดิเตอร์ สำหรับตัวเลือกเทมเพลตของคุณเอง เป็น null สำหรับเทมเพลต HTML

## คำขอแรกของคุณ

บันทึกอีเมลต้อนรับที่มีตัวแปรสองตัว แทนที่ `SENDCOREX_API_KEY` ด้วย API key ของคุณ

```
curl -X POST 'https://g.sendcorex.com/v1/template' \
  -H "Authorization: $SENDCOREX_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "commands": [
    { "command": "create_template", "args": { "name": "Welcome email", "subject": "Welcome, {{first_name}}", "html": "<h1>Hi {{first_name}}</h1><p>Your {{plan}} plan is ready.</p>" } }
  ]
}'
```

คุณจะได้เทมเพลตกลับมาพร้อม template_id เรนเดอร์ด้วยตัวแปรเพื่อดูอีเมลสุดท้าย คำขอเดียวกันใน 8 ภาษาอยู่ใน [Create Template](https://docs.sendcorex.com/th/api-reference/templates/editing/create-template) .

## งานที่ใช้บ่อย

เทมเพลตเป็นโค้ด

เก็บ HTML ใน repo และ push ด้วย Update Template ทุกครั้งที่ deploy รีวิวเหมือนการเปลี่ยนแปลงอื่น

[เก็บเทมเพลตไว้ใน repo ของคุณ](https://docs.sendcorex.com/th/api-reference/templates/editing/update-template#deploys)

ยกเลิกการเปลี่ยนที่ผิด

แสดงรายการเวอร์ชันแล้วกู้คืนเวอร์ชันที่ดีล่าสุด การกู้คืนก็เป็นเวอร์ชันหนึ่ง จึงยกเลิกได้

[กู้คืนเวอร์ชันเทมเพลต](https://docs.sendcorex.com/th/api-reference/templates/versions/restore-template-version)

ใช้สิ่งที่ทีมของคุณออกแบบ

ทีมการตลาดสร้างอีเมลในเอดิเตอร์ โค้ดของคุณอ่านด้วย Get Template แล้วส่ง

[Get Template](https://docs.sendcorex.com/th/api-reference/templates/templates/get-template)

จับข้อมูลที่ขาด

missing_variables แสดง {{variable}} ทุกตัวที่คุณไม่ได้เติม ตรวจสอบก่อนส่ง

[ตัวแปร](https://docs.sendcorex.com/th/api-reference/templates/templates/render-template#variables)

## ข้อมูลอ้างอิงฉบับเต็ม

ทุกอย่างที่มีเครื่องหมาย CMD คือคำสั่งที่ส่งผ่าน POST /v1/template, up to 10 per request

### เส้นทาง

1

- [POST Run Commands1 ถึง 10 คำสั่งต่อคำขอ](https://docs.sendcorex.com/th/api-reference/templates/routes/run-commands)

### เทมเพลต

3

- [CMD List Templatesทุกเทมเพลต ไม่รวม HTML](https://docs.sendcorex.com/th/api-reference/templates/templates/list-templates)
- [CMD Get Templateเทมเพลตหนึ่งรายการพร้อม html, text และ subject](https://docs.sendcorex.com/th/api-reference/templates/templates/get-template)
- [CMD Render Templateเติมตัวแปร ไม่มีการส่ง](https://docs.sendcorex.com/th/api-reference/templates/templates/render-template)

### การแก้ไข

3

- [CMD Create Templateบันทึก HTML ของคุณเอง](https://docs.sendcorex.com/th/api-reference/templates/editing/create-template)
- [CMD Update Templateแก้ไข แล้วระบบบันทึกเวอร์ชันให้](https://docs.sendcorex.com/th/api-reference/templates/editing/update-template)
- [CMD Delete Templateลบเทมเพลตและทุกเวอร์ชัน](https://docs.sendcorex.com/th/api-reference/templates/editing/delete-template)

### เวอร์ชัน

2

- [CMD List Template Versions10 เวอร์ชันที่บันทึกล่าสุด](https://docs.sendcorex.com/th/api-reference/templates/versions/list-template-versions)
- [CMD Restore Template Versionย้อนกลับไปยังเวอร์ชันหนึ่ง](https://docs.sendcorex.com/th/api-reference/templates/versions/restore-template-version)
