メールの受信:読み取り

List Threads

フォルダーの会話をGmailのように一覧表示します。未読、スター、重要、添付ファイル、日付で絞り込めます。

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

各項目は会話です。last_message_uidを使ってget_threadまたはget_messagesで開きます。

引数

  • 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)、エポックミリ秒。

    例: "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

    get_messagesやget_threadで会話を開くためのid。

  • threads[].last_message_at

    最新メッセージの日付。

  • has_more / next_cursor

    ページネーション。次のページを取得するにはnext_cursorをcursorとして送ります。

絞り込みと速度

is_read: false、is_starred: true、is_important: trueは専用のインデックスを使うため、フォルダー全体ではなく一致する会話だけを調べます。組み合わせると1つのインデックス(スター、重要、未読の順)を使い、残りはその上で絞り込みます。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は、Run Commandsのように{ commands: [...] }を/v1にPOSTしてresultsを返す任意のヘルパーです。

エラー

HTTPレベルのエラーはtype、code、messageを返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

  • 401TOKEN_EXPIRED

    access tokenの有効期限が切れました。Refresh Tokenを呼んでリクエストを繰り返してください。

  • 401INVALID_TOKEN

    トークンの形式が不正、不明、または取り消されています。

  • 429RATE_LIMITED

    同じIP + メールボックスで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。

  • CMDINVALID_ARGS

    必須の引数がないか不正です。

  • CMDINVALID_CURSOR

    カーソルが不正か、別のアカウントまたはフォルダーのものです。

  • CMDINTERNAL

    サーバーエラー。詳細はサーバーのログにのみ記録されます。