---
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/receive-emails/flags-labels/set-flags

รับอีเมล: แฟล็กและป้ายกำกับ

# Set Flags

ทำเครื่องหมายข้อความว่าอ่านแล้วหรือยังไม่อ่าน ติดดาว และสำคัญ ใช้กับข้อความเดียวหรือแบบกลุ่ม

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

คำสั่งแบบกลุ่มตอบทีละรายการ id ที่หายไปหนึ่งรายการจึงไม่ทำให้รายการอื่นล้มเหลว

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

- `ids` string[] ไม่บังคับ
id ข้อความสูงสุด 100 รายการ
- `id` string ไม่บังคับ
id ข้อความเดียว ใช้อันนี้หรือ `ids`
- `is_read` boolean ไม่บังคับ
ทำเครื่องหมายว่าอ่านแล้ว (`true`) หรือยังไม่อ่าน (`false`)
- `is_starred` boolean ไม่บังคับ
เพิ่มหรือเอาดาวออก
- `is_important` boolean ไม่บังคับ
เพิ่มหรือเอาแฟล็กสำคัญออก
- `scope` string ไม่บังคับ
`message` (ค่าเริ่มต้น) หรือ `thread` มีผลเฉพาะ `is_read`

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "set_flags",
        args: {
          ids: [
            "Vj0xQUJDMTIz"
          ],
          is_read: true,
          scope: "thread"
        }
      }
    ]
  },
  { 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);
```

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

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "set_flags",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "items": [
          {
            "id": "Vj0xQUJDMTIz",
            "ok": true,
            "data": {
              "changed": 2
            }
          }
        ],
        "ok_count": 1,
        "failed_count": 0
      }
    }
  ]
}
```

### ฟิลด์การตอบกลับ

- `items[].id`
id ที่รายการนี้อ้างถึง
- `items[].ok`
`true` หากการเปลี่ยนแปลงสำเร็จสำหรับ id นี้
- `items[].data`
ผลลัพธ์ของ id นี้ เฉพาะเมื่อ `ok` เป็น `true`
- `items[].code / message`
ข้อผิดพลาดของ id นี้ เฉพาะเมื่อ `ok` เป็น `false`
- `ok_count / failed_count`
จำนวน id ที่สำเร็จและล้มเหลว

## แฟล็กทำงานอย่างไร

- `is_read + scope: thread`
ทำเครื่องหมายทั้งบทสนทนา
- `is_starred / is_important: true`
ทำเครื่องหมายเฉพาะข้อความของ `id`
- `is_starred / is_important: false`
ล้างแฟล็กทั้งบทสนทนา แถวบทสนทนาแสดง "มีดาว" การเอาดาวออกจึงต้องล้างทุกข้อความ

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

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

- 401`TOKEN_EXPIRED`
access token หมดอายุแล้ว เรียก Refresh Token แล้วส่งคำขอซ้ำ
- 401`INVALID_TOKEN`
โทเค็นผิดรูปแบบ ไม่รู้จัก หรือถูกเพิกถอน
- 429`RATE_LIMITED`
เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + กล่องจดหมายเดียวกัน รอจำนวนวินาทีใน Retry-After
- CMD`INVALID_ARGS`
อาร์กิวเมนต์ที่จำเป็นหายไปหรือไม่ถูกต้อง
- CMD`NOT_FOUND`
ไม่มีข้อความ เธรด หรือโฟลเดอร์นี้สำหรับโทเค็นนี้
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
