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

Mẫu

# Các mẫu của bạn, từ trình soạn thảo hoặc từ mã

Đọc các mẫu nhóm của bạn tạo trong trình soạn thảo của dashboard, hoặc mang HTML của bạn và quản lý nó như mã: biến, kiểm tra khi lưu và phiên bản để quay lại.

- Lệnh JSON
- Mang HTML của riêng bạn
- Biến
- 10 phiên bản
- Kiểm tra khi lưu

Bắt đầu Xem các lệnh

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

## Cách hoạt động

Ba loại, một API

Kéo thả (Unlayer), trình soạn thảo Sendcorex (Custom) và HTML của riêng bạn đều được liệt kê, đọc và kết xuất theo cùng một cách.

Không bị khóa vào trình soạn thảo

Bạn tạo email bằng MJML, React Email hay nhà thiết kế? Hãy gửi HTML. Nó được kiểm tra khi lưu theo cùng quy tắc như khi gửi, nên mẫu lưu được là mẫu gửi được.

Có sẵn phiên bản

Mỗi thay đổi của mẫu HTML lưu một phiên bản. Một lần deploy hỏng chỉ cần một Restore Template Version để sửa.

## Bắt đầu

Trước yêu cầu đầu tiên chỉ cần key.

1. 1
Tạo API key có scope mẫu
Trong dashboard, mở Developers → API Keys và cấp cho key template:read, cùng template:create, template:update và template:delete nếu nó quản lý HTML của riêng bạn.
Token webmail không dùng được ở đây. API này dùng API key từ dashboard.
[Mở API Keys](https://app.sendcorex.com/dashboard/developer)
2. 2
Lưu HTML của bạn
Create Template với tên và HTML. Dùng {{variables}} cho những gì thay đổi theo từng email.
[Create Template](https://docs.sendcorex.com/vi/api-reference/templates/editing/create-template)
3. 3
Kết xuất và gửi
Render Template điền các biến và cho bạn biết biến nào còn thiếu. Truyền kết quả cho Send Email.
[Render mẫu](https://docs.sendcorex.com/vi/api-reference/templates/templates/render-template) [Gửi email](https://docs.sendcorex.com/vi/api-reference/email/send)

## Mẫu

Get Template, Create Template và Update Template trả về cấu trúc này. List Templates trả về nó nhưng không có subject, html và 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> hoặc custom_<uuid>. Tiền tố là loại mẫu.

`editable`

true với HTML của riêng bạn. Mẫu của trình soạn thảo chỉ đọc qua API.

`{{variables}}`

Placeholder trong subject, html và text, được Render Template điền.

`preview`

Ảnh xem trước của mẫu trình soạn thảo, cho bộ chọn mẫu của riêng bạn. null với mẫu HTML.

## Yêu cầu đầu tiên

Lưu một email chào mừng với hai biến. Thay `SENDCOREX_API_KEY` bằng API key của bạn.

```
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>" } }
  ]
}'
```

Bạn nhận lại mẫu kèm template_id của nó. Kết xuất nó với các biến để xem email cuối cùng. Cùng yêu cầu bằng 8 ngôn ngữ có trong [Create Template](https://docs.sendcorex.com/vi/api-reference/templates/editing/create-template) .

## Tác vụ thường gặp

Mẫu dưới dạng mã

Giữ HTML trong repo và đẩy lên bằng Update Template mỗi lần deploy. Được xem xét như mọi thay đổi.

[Giữ mẫu trong repo của bạn](https://docs.sendcorex.com/vi/api-reference/templates/editing/update-template#deploys)

Hoàn tác một thay đổi sai

Liệt kê các phiên bản và khôi phục phiên bản tốt gần nhất. Việc khôi phục cũng là một phiên bản, nên có thể hoàn tác.

[Khôi phục phiên bản mẫu](https://docs.sendcorex.com/vi/api-reference/templates/versions/restore-template-version)

Dùng những gì nhóm bạn thiết kế

Marketing tạo email trong trình soạn thảo; mã của bạn đọc nó bằng Get Template và gửi đi.

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

Phát hiện dữ liệu thiếu

missing_variables liệt kê mọi {{variable}} bạn chưa điền. Hãy kiểm tra trước khi gửi.

[Biến](https://docs.sendcorex.com/vi/api-reference/templates/templates/render-template#variables)

## Tham chiếu đầy đủ

Mọi mục đánh dấu CMD là lệnh gửi qua POST /v1/template, up to 10 per request.

### Tuyến

1

- [POST Run Commands1 đến 10 lệnh mỗi yêu cầu](https://docs.sendcorex.com/vi/api-reference/templates/routes/run-commands)

### Mẫu

3

- [CMD List TemplatesMọi mẫu, không có HTML](https://docs.sendcorex.com/vi/api-reference/templates/templates/list-templates)
- [CMD Get TemplateMột mẫu với html, text và subject](https://docs.sendcorex.com/vi/api-reference/templates/templates/get-template)
- [CMD Render TemplateĐiền biến, không gửi gì](https://docs.sendcorex.com/vi/api-reference/templates/templates/render-template)

### Chỉnh sửa

3

- [CMD Create TemplateLưu HTML của riêng bạn](https://docs.sendcorex.com/vi/api-reference/templates/editing/create-template)
- [CMD Update TemplateThay đổi nó, một phiên bản được lưu](https://docs.sendcorex.com/vi/api-reference/templates/editing/update-template)
- [CMD Delete TemplateXóa nó và các phiên bản](https://docs.sendcorex.com/vi/api-reference/templates/editing/delete-template)

### Phiên bản

2

- [CMD List Template Versions10 phiên bản đã lưu gần nhất](https://docs.sendcorex.com/vi/api-reference/templates/versions/list-template-versions)
- [CMD Restore Template VersionQuay lại một trong số đó](https://docs.sendcorex.com/vi/api-reference/templates/versions/restore-template-version)
