# threads.list

List conversation threads.

Returns conversation threads, newest activity first, one row per conversation: participants, message and unread counts, and an exemplar message carrying the subject and snippet a row renders. Grouping is by REPLY CHAIN (In-Reply-To/References), never by subject — two unrelated messages sharing a subject are two conversations, and a renamed reply stays in the one it answers. Filtering by `label` and by unread/starred flags uses Gmail semantics: a conversation matches when ANY of its live members does, and the counts then span the whole conversation — but the exemplar is the newest member that MATCHED, so a label-filtered row is faced with the message that folder actually holds. See ThreadListItem.exemplar. Trash and Junk are HIDDEN ROLES: outside their own views a conversation is its live members carrying neither label — they do not qualify a row, are not counted, faced or listed in `participants`/`labels`. `label=Trash` lists conversations by their trashed members and `label=Junk` by their junked ones; a member in both is in the bin (shown in Trash, hidden in Junk). `excludeRoles` adds to that rule and never lifts it.

```ts
openemail.threads.list(
  mailboxId: string,
  options?: ThreadsListOptions,
): PagePromise<ThreadsListResult, ThreadListItem>
```

It calls `GET /mailboxes/{mailboxId}/threads`: [List conversation threads](/docs/api/threads/get_ThreadList) in the API reference.

## Example

```ts
for await (const threadListItem of openemail.threads.list(mailboxId)) {
  // every item of every page (await the call instead for one page)
}
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `mailboxId` | `string` | Mailbox ULID identifier. The path's `{mailboxId}`. |

## Options

The last argument, `options`, a `ThreadsListOptions`, takes:

| Option | Type | Sent as | Description |
| --- | --- | --- | --- |
| `label` | `string` | query `label` | Filter threads containing messages with this label (e.g. INBOX) |
| `excludeRoles` | `('inbox' \| 'sent' \| 'drafts' \| 'trash' \| 'archive' \| 'junk')[]` | query `excludeRoles` | System label roles to exclude: 'inbox', 'sent', 'drafts', 'trash', 'archive', 'junk' (e.g. 'trash,junk'). Unknown roles return 400 validation_failed. |
| `cursor` | `string` | query `cursor` | Pagination cursor from previous page |
| `limit` | `number` | query `limit` | Maximum threads to return per page (max 100) |
| `order` | `('asc' \| 'desc')` | query `order` | Listing direction: desc (default) = newest first, asc = oldest first. Hold it constant across a cursor crawl — cursors do not encode direction, so switching mid-crawl re-windows the page rather than erroring |
| `sortBy` | `('arrival' \| 'date')` | query `sortBy` | Sort key: arrival (default) = the order mail reached this mailbox (message id); date = the Date header, falling back to arrival where it is absent or unparseable (RFC 5256 SORT DATE). Cursors follow the key, so hold it constant across a crawl — unlike order, a mismatched cursor is refused with 400 invalid_cursor rather than silently re-windowing. Note that under arrival an imported message (APPEND with ?internaldate=) lists where it was imported, not at its receivedAt; date orders imported mail by its own header |
| `hasFlags` | `string` | query `hasFlags` | Comma-separated flag names; a message matches only if ALL are set (e.g. flagged) |
| `notFlags` | `string` | query `notFlags` | Comma-separated flag names; a message matches only if NONE are set (e.g. seen, for unread-only) |

Every call also takes `signal`, `timeout`, `retry` and `headers`, which say how that one call is sent ([call options](/docs/sdks/typescript/calling-methods#call-options)).

## Answer

It is a listing, a [`PagePromise`](/docs/sdks/typescript/listings). Awaited, it is one page as the API answers it, [`ThreadsListResult`](#threadslistresult). Iterated with `for await`, it is every [`ThreadListItem`](/docs/sdks/typescript/types/thread-list-item) of every page, each page fetched as the loop reaches it.

## Errors

| Status | What it means |
| --- | --- |
| `400` | validation_failed — invalid query parameters or mismatched cursor |
| `401` | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge |
| `404` | Mailbox not found or label not found |
| `503` | temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description) |

A failed call rejects with a [`RequestError`](/docs/sdks/typescript/errors): its `status`, and its `code`, the API's `error`. Decide on the code: one status covers several.

## Types

### ThreadsListResult

```ts
/** What `threads.list` answers. */
type ThreadsListResult = {
  /** Opaque cursor for the next page; absent on the last page */
  nextCursor?: string
  threads: ThreadListItem[]
}
```

It names these types of the API, each on a page of its own: [`ThreadListItem`](/docs/sdks/typescript/types/thread-list-item).
