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

List Threads

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

POSThttps://g.sendcorex.com/v1command: list_threads

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

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

  • folderstringไม่บังคับ

    โฟลเดอร์ที่จะแสดง ค่าเริ่มต้น INBOX

  • limitnumberไม่บังคับ

    ขนาดหน้า 1 ถึง 100 ค่าเริ่มต้น 25

  • cursorstringไม่บังคับ

    next_cursor ของหน้าก่อน

  • is_readbooleanไม่บังคับ

    false ส่งเฉพาะบทสนทนาที่มีข้อความยังไม่อ่าน

  • is_starredbooleanไม่บังคับ

    กรองตามดาว

  • is_importantbooleanไม่บังคับ

    กรองตามความสำคัญ

  • has_attachmentsbooleanไม่บังคับ

    กรองตามไฟล์แนบ

  • afterstringไม่บังคับ

    เฉพาะบทสนทนาที่ข้อความล่าสุดอยู่ในหรือหลังวันนี้ (รวมวันนี้) RFC 3339, YYYY-MM-DD (UTC) หรือ epoch มิลลิวินาที

    เช่น "2026-10-01"

  • beforestringไม่บังคับ

    เฉพาะบทสนทนาที่ข้อความล่าสุดอยู่ก่อนวันนี้ (ไม่รวม) รูปแบบเดียวกับ 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

  • 401TOKEN_EXPIRED

    access token หมดอายุแล้ว เรียก Refresh Token แล้วส่งคำขอซ้ำ

  • 401INVALID_TOKEN

    โทเค็นผิดรูปแบบ ไม่รู้จัก หรือถูกเพิกถอน

  • 429RATE_LIMITED

    เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + กล่องจดหมายเดียวกัน รอจำนวนวินาทีใน Retry-After

  • CMDINVALID_ARGS

    อาร์กิวเมนต์ที่จำเป็นหายไปหรือไม่ถูกต้อง

  • CMDINVALID_CURSOR

    cursor ผิดรูปแบบหรือเป็นของบัญชีหรือโฟลเดอร์อื่น

  • CMDINTERNAL

    ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์