---
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/reading/list-threads

รับอีเมล: การอ่าน

# List Threads

แสดงบทสนทนาของโฟลเดอร์แบบ Gmail พร้อมตัวกรองยังไม่อ่าน ติดดาว สำคัญ ไฟล์แนบ และวันที่

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

แต่ละรายการคือบทสนทนา เปิดด้วย `get_thread` หรือ `get_messages` โดยใช้ `last_message_uid`

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

- `folder` string ไม่บังคับ
โฟลเดอร์ที่จะแสดง ค่าเริ่มต้น `INBOX`
- `limit` number ไม่บังคับ
ขนาดหน้า 1 ถึง 100 ค่าเริ่มต้น 25
- `cursor` string ไม่บังคับ
`next_cursor` ของหน้าก่อน
- `is_read` boolean ไม่บังคับ
`false` ส่งเฉพาะบทสนทนาที่มีข้อความยังไม่อ่าน
- `is_starred` boolean ไม่บังคับ
กรองตามดาว
- `is_important` boolean ไม่บังคับ
กรองตามความสำคัญ
- `has_attachments` boolean ไม่บังคับ
กรองตามไฟล์แนบ
- `after` string ไม่บังคับ
เฉพาะบทสนทนาที่ข้อความล่าสุดอยู่ในหรือหลังวันนี้ (รวมวันนี้) RFC 3339, `YYYY-MM-DD` (UTC) หรือ epoch มิลลิวินาที
เช่น `"2026-10-01"`
- `before` string ไม่บังคับ
เฉพาะบทสนทนาที่ข้อความล่าสุดอยู่ก่อนวันนี้ (ไม่รวม) รูปแบบเดียวกับ `after`
เช่น `"2026-10-08T00:00:00+08:00"`

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "list_threads",
        args: {
          folder: "INBOX",
          is_read: false,
          limit: 20
        }
      }
    ]
  },
  { 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": "list_threads",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "threads": [
          {
            "thread_id": "thr_9a1c4e72",
            "folder": "INBOX",
            "subject": "Invoice for September",
            "preview": "Hi, attached is the invoice for September…",
            "from_name": "Ana Costa",
            "from_email": "ana@client.com",
            "participants": [
              "ana@client.com",
              "you@yourdomain.com"
            ],
            "last_senders": [
              "ana@client.com"
            ],
            "message_count": 2,
            "thread_message_count": 3,
            "unread_count": 1,
            "has_unread": true,
            "has_starred": false,
            "has_important": false,
            "has_attachments": false,
            "last_message_uid": "Vj0xQUJDMTIz",
            "last_message_at": "2026-10-09T14:21:07Z"
          }
        ],
        "has_more": true,
        "next_cursor": "eyJwIjoyfQ"
      }
    }
  ]
}
```

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

- `threads[].thread_id`
id ของบทสนทนา
- `threads[].folder`
โฟลเดอร์ที่กำลังแสดง
- `threads[].subject`
หัวเรื่องของบทสนทนา
- `threads[].preview`
ตัวอย่างสั้นของข้อความล่าสุด
- `threads[].from_name / from_email`
ผู้ส่งข้อความล่าสุด
- `threads[].participants`
ทุกคนในบทสนทนา
- `threads[].last_senders`
ผู้เขียนข้อความล่าสุด
- `threads[].message_count`
ข้อความในโฟลเดอร์นี้
- `threads[].thread_message_count`
ข้อความในบทสนทนาทั้งหมด
- `threads[].unread_count / has_unread`
ข้อความที่ยังไม่อ่านในบทสนทนา
- `threads[].has_starred / has_important / has_attachments`
แฟล็กของบทสนทนา
- `threads[].last_message_uid`
id สำหรับเปิดบทสนทนาด้วย `get_messages` หรือ `get_thread`
- `threads[].last_message_at`
วันที่ของข้อความล่าสุด
- `has_more / next_cursor`
การแบ่งหน้า ส่ง `next_cursor` เป็น `cursor` เพื่อดูหน้าถัดไป

## ตัวกรองและความเร็ว

`is_read: false`, `is_starred: true` และ `is_important: true` ใช้ดัชนีของตัวเอง จึงตรวจเฉพาะบทสนทนาที่ตรง ไม่ใช่ทั้งโฟลเดอร์ หากรวมกัน จะใช้ดัชนีเดียว (ดาว แล้วสำคัญ แล้วยังไม่อ่าน) และกรองส่วนที่เหลือต่อ `after` และ `before` เป็นช่วงคีย์ จึงไม่สแกนนอกช่วงเวลา `has_attachments` และค่า `false` ของดาวและสำคัญยังสแกนโฟลเดอร์

บทสนทนาที่ยังไม่อ่านในช่วงวันที่

```
{
  "commands": [
    {
      "command": "list_threads",
      "args": {
        "is_read": false,
        "after": "2026-10-01",
        "before": "2026-10-08T00:00:00+08:00"
      }
    }
  ]
}
```

## การแบ่งหน้า

เมื่อ `has_more` เป็น `true` เรียกคำสั่งอีกครั้งโดยตั้ง `cursor` เป็น `next_cursor`

Node.js

```
let cursor;
const threads = [];

do {
  const [result] = await call({
    command: 'list_threads',
    args: { folder: 'INBOX', limit: 100, ...(cursor ? { cursor } : {}) },
  });
  threads.push(...result.data.threads);
  cursor = result.data.has_more ? result.data.next_cursor : null;
} while (cursor);
```

`call` คือตัวช่วยใดก็ได้ที่ POST `{ commands: [...] }` ไปที่ `/v1` และส่งกลับ `results` เหมือนใน Run Commands

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

ข้อผิดพลาดระดับ 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`INVALID_CURSOR`
cursor ผิดรูปแบบหรือเป็นของบัญชีหรือโฟลเดอร์อื่น
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
