---
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/receive-emails/templates/create-template

Nhận email: mẫu

# Create Template

Lưu thư trả lời bạn hay gửi. Placeholder như {first_name} được điền khi dùng.

POST `https://g.sendcorex.com/v1` command: create_template

Placeholder: `{first_name}`, `{last_name}`, `{name}`, `{email}` và bất kỳ tên nào bạn truyền trong `variables` khi dùng.

## Tham số

- `name` string bắt buộc
Tối đa 80 ký tự.
- `body_html` string bắt buộc
Tối đa 64 KB. Hoặc `text`.
- `subject` string không bắt buộc
Điền tiêu đề của email mới. Tối đa 200 ký tự.

## Bắt đầu nhanh

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "create_template",
        args: {
          name: "Pricing reply",
          subject: "Our pricing",
          body_html: "<p>Hi {first_name},</p><p>Here is our pricing…</p>"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);
```

## Phản hồi

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "create_template",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "id": "Vj0xVFBMMDAx",
        "template_id": "Vj0xVFBMMDAx",
        "name": "Pricing reply",
        "subject": "Our pricing",
        "body_html": "<p>Hi {first_name},</p><p>Here is our pricing…</p>",
        "use_count": 14,
        "last_used_at": "2026-10-24T03:10:00Z",
        "created_at": "2026-09-02T01:00:00Z",
        "updated_at": "2026-10-01T05:00:00Z"
      }
    }
  ]
}
```

## Lỗi

Lỗi ở mức HTTP trả về `type`, `code` và `message`. Lỗi đánh dấu CMD được trả về trong kết quả lệnh, với HTTP 200.

- 401`TOKEN_EXPIRED`
Access token đã hết hạn. Gọi Refresh Token và lặp lại yêu cầu.
- 401`INVALID_TOKEN`
Token sai định dạng, không xác định hoặc đã bị thu hồi.
- 429`RATE_LIMITED`
Hơn 15 yêu cầu/giây hoặc 15 yêu cầu đồng thời cho cùng IP + hộp thư. Chờ số giây trong Retry-After.
- CMD`INVALID_ARGS`
Thiếu hoặc sai tham số bắt buộc.
- CMD`LIMIT`
Hộp thư đã đạt giới hạn (100 quy tắc, 200 mẫu hoặc 100 nhãn).
- CMD`INTERNAL`
Lỗi máy chủ. Chi tiết chỉ được ghi vào log máy chủ.
