---
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/versions/restore-template-version

เทมเพลต: เวอร์ชัน

# กู้คืนเวอร์ชันเทมเพลต

นำเทมเพลต HTML กลับไปยังเวอร์ชันก่อนหน้า: html, text และ subject การกู้คืนเองจะกลายเป็นเวอร์ชันล่าสุด จึงยกเลิกได้เช่นกัน

POST `https://g.sendcorex.com/v1/template` command: restore_template_version

ต้องมีขอบเขต `template:update` บน API key ของคุณ

สูงสุด 20 ครั้งต่อนาทีต่อบัญชี หากเกิน คำสั่งจะตอบ `RATE_LIMITED`

## อาร์กิวเมนต์

- `template_id` string จำเป็น
เทมเพลต HTML
เช่น `"html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93"`
- `version_at` string จำเป็น
`version_at` จาก List Template Versions ตามที่ได้รับมา
เช่น `"2026-10-21T04:09:12.004Z"`

## เริ่มต้นอย่างรวดเร็ว

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "restore_template_version",
        args: {
          template_id: "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
          version_at: "2026-10-21T04:09:12.004Z"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

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

## การตอบกลับ

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "restore_template_version",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 11,
      "data": {
        "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:40:02.118Z",
        "subject": "Welcome to Acme",
        "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`
id ของเทมเพลต: `html_<uuid>`, `unlayer_<number>` หรือ `custom_<uuid>` ใช้ในทุกคำสั่งอื่น
- `type`
`html` (ของคุณ ส่งผ่าน API), `unlayer` (สร้างในเอดิเตอร์แบบลากและวาง) หรือ `custom` (สร้างในเอดิเตอร์ของ Sendcorex)
- `name`
ชื่อที่คุณตั้ง
- `reference`
รหัสสั้นที่ใช้ระบุเทมเพลตในแดชบอร์ดด้วย
- `preview`
ภาพตัวอย่างของเทมเพลต สำหรับเทมเพลตจากเอดิเตอร์ เป็น `null` สำหรับเทมเพลต HTML และเทมเพลตจากเอดิเตอร์ที่ยังไม่บันทึก
- `has_html`
`false` สำหรับเทมเพลตจากเอดิเตอร์ที่สร้างแล้วแต่ไม่เคยบันทึก ยังเรนเดอร์หรือส่งไม่ได้
- `html_size`
ขนาดของ HTML เป็นไบต์
- `editable`
`true` สำหรับเทมเพลต HTML: อัปเดต กู้คืน และลบได้ที่นี่ เทมเพลตจากเอดิเตอร์อ่านได้อย่างเดียวผ่าน API
- `created_at / updated_at`
ISO 8601, UTC
- `subject`
หัวเรื่องเริ่มต้น หรือ `null` มีตัวแปรได้
- `html`
HTML เป็น `null` สำหรับเทมเพลตจากเอดิเตอร์ที่ไม่เคยบันทึก
- `text`
เวอร์ชันข้อความธรรมดา หรือ `null` ควรส่งด้วย: บางโปรแกรมและตัวกรองชอบอีเมลที่มีเวอร์ชันนี้

## ข้อผิดพลาด

ข้อผิดพลาดระดับ HTTP ส่งกลับ `type`, `code` และ `message` ข้อผิดพลาดที่มีเครื่องหมาย CMD จะกลับมาในผลลัพธ์ของคำสั่ง พร้อม HTTP 200

- 401`INVALID_API_KEY`
API key ไม่มีอยู่ ถูกเพิกถอน หรือถูกปิดในแดชบอร์ด
- 429`RATE_LIMITED`
เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + API key เดียวกัน รอจำนวนวินาทีใน Retry-After
- CMD`MISSING_SCOPE`
API key ไม่มีขอบเขตที่คำสั่งนี้ต้องการ
- CMD`INVALID_ARGS`
อาร์กิวเมนต์ไม่ถูกต้อง: `template_id` รูปแบบผิด ไม่มี `name` หรือ `html` ชื่อยาวเกิน 255 ตัวอักษร `version_at` ที่ไม่ใช่ RFC 3339…
- CMD`TEMPLATE_NOT_FOUND`
เทมเพลตไม่อยู่ในบัญชีของคุณ
- CMD`TEMPLATE_READ_ONLY`
เทมเพลต Unlayer หรือ Custom: แก้ไขในเอดิเตอร์ของแดชบอร์ด ผ่าน API เปลี่ยนได้เฉพาะเทมเพลต HTML
- CMD`VERSION_NOT_FOUND`
ไม่มีเวอร์ชันนั้น เก็บไว้เฉพาะ 10 เวอร์ชันล่าสุด
- CMD`RATE_LIMITED`
บัญชีของคุณเรียกคำสั่งนี้บ่อยเกินไปในนาทีที่ผ่านมา รอหนึ่งนาที
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
