---
title: "Mail"
description: "Threads, messages, raw and HTML bodies, attachments and their extracted text."
url: https://doorman.fyi/docs/reference/mail
markdown: https://doorman.fyi/docs/reference/mail.md
area: "API reference"
section: "API reference"
---

# Mail

Threads, messages, raw and HTML bodies, attachments and their extracted text.

Source: https://doorman.fyi/docs/reference/mail

## List threads

`GET /v1/inboxes/{inboxId}/threads`

Access `any`: any API key, or a console session.

The inbox's threads, newest activity first. Filter by read state, or search the subject and participants. Trashed threads are left out.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.inboxes.threads.list`](https://doorman.fyi/docs/sdk/reference/mail.md#inboxes-threads-list) in TypeScript, [`client.inboxes.threads.list`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-threads-list) in Python, the [`inboxes_threads_list`](https://doorman.fyi/docs/mcp/tools/mail.md#inboxes-threads-list) tool and [`doorman inboxes threads list`](https://doorman.fyi/docs/cli/commands/mail.md#inboxes-threads-list) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `inboxId` | path | `string` | yes | The inbox. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`. |
| `isRead` | query | `"true" \| "false"` | no | Only read or only unread threads. |
| `q` | query | `string` | no | Keep the threads whose subject or a participant address contains this text, case-insensitively. |
| `label` | query | `string` | no | Only threads containing this exact, case-sensitive label. Example: `needs-review`. |
| `limit` | query | `integer` | no | Page size, 1 to 100. Defaults to 50. |
| `offset` | query | `integer` | no | Rows to skip. Defaults to 0. |

Answers `200`: A page of threads.

**Response 200: ThreadPage**
A page of an inbox's threads, newest activity first. Trashed threads are left out.
- `data` (Thread[])
- `limit` (integer): The page size that was applied.
- `offset` (integer): The offset that was applied.
- `total` (integer): How many threads match, across every page.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | A field is missing or invalid; the message names it. |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## List threads a person has or has not seen

`GET /v1/inboxes/{inboxId}/threads/by-seen`

Access `session`: a console session only; an API key gets 403 `session_required`.

The inbox's threads, newest activity first, kept by a person's own mark: those somebody looked at in the console since mail last arrived in them, or those nobody has. It is the console's list of what is new to a person, and says nothing about `isRead`, which agents poll. Trashed threads are left out.

OAuth: not available to delegated app tokens.

Also available as [`client.inboxes.threads.listBySeen`](https://doorman.fyi/docs/sdk/reference/mail.md#inboxes-threads-listBySeen) in TypeScript and [`client.inboxes.threads.list_by_seen`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-threads-listBySeen) in Python.

Organizations: a member's console session needs `mail:read`. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `inboxId` | path | `string` | yes | The inbox. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`. |
| `isSeen` | query | `"true" \| "false"` | yes | `false` for the threads nobody has looked at, `true` for the others. |
| `q` | query | `string` | no | Keep the threads whose subject or a participant address contains this text, case-insensitively. |
| `label` | query | `string` | no | Only threads containing this exact, case-sensitive label. Example: `needs-review`. |
| `limit` | query | `integer` | no | Page size, 1 to 100. Defaults to 50. |
| `offset` | query | `integer` | no | Rows to skip. Defaults to 0. |

Answers `200`: A page of threads.

**Response 200: ThreadPage**
A page of an inbox's threads, newest activity first. Trashed threads are left out.
- `data` (Thread[])
- `limit` (integer): The page size that was applied.
- `offset` (integer): The offset that was applied.
- `total` (integer): How many threads match, across every page.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | A field is missing or invalid; the message names it. |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `session_required` | Account keys, developer apps, relying parties, installations, consent, approving a sign-in and the assistant require a console session. So does loosening the security policy, trusting a sender, releasing held mail, allowing a sign-in, letting agents sign in to new services alone or telling a service who owns an agent, unless the account allows its account keys to. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads/by-seen" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads/by-seen", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/threads/by-seen",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Read a thread

`GET /v1/threads/{threadId}`

Access `any`: any API key, or a console session.

One thread's summary. Its messages are at `/v1/threads/{threadId}/messages`.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.threads.get`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-get) in TypeScript, [`client.threads.get`](https://doorman.fyi/docs/python/reference/mail.md#threads-get) in Python, the [`threads_get`](https://doorman.fyi/docs/mcp/tools/mail.md#threads-get) tool and [`doorman threads get`](https://doorman.fyi/docs/cli/commands/mail.md#threads-get) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

Answers `200`: The thread.

**Response 200: Thread**
A conversation: the messages that reply to each other, or share a subject and a participant.
- `id` (string): A thread identifier. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`
- `inboxId` (string): An inbox identifier. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`
- `subject` (string): The subject of the first message. Example: `Invoice 2847`
- `participants` (string[]): Every address seen in the thread other than the inbox's own, sorted. Example: `["sam@example.com"]`
- `messageCount` (integer)
- `isRead` (boolean): False until the thread is marked read or a reply is sent.
- `isSeen` (boolean, optional): Whether a person has looked at the thread in the console since mail last arrived in it. It is the console's own mark and says nothing about `isRead`, which is what an agent polls: a person looking at a thread does not mark it read. Older deployments omit it.
- `metadata` (Metadata, optional)
- `labels` (ThreadLabels, optional)
- `riskLevel` ("low" | "medium" | "high" | "critical" | null, optional): The highest risk level among the thread's inbound messages that the owner has not marked safe; null when none was assessed. Older deployments omit it.
- `firstMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageId` (string | null)
- `createdAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`

Example 200 response:
```json
{
  "id": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "subject": "Invoice 2847",
  "participants": [
    "sam@example.com"
  ],
  "messageCount": 1,
  "isRead": false,
  "metadata": {},
  "labels": [],
  "riskLevel": "low",
  "firstMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageId": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "createdAt": "2026-11-05T10:05:00.000Z"
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Update a thread

`PATCH /v1/threads/{threadId}`

Access `any`: any API key, or a console session.

Sets read state, metadata or labels. Omitted fields stay unchanged; metadata and labels replace the whole value, with {} or [] clearing it. Sending a reply marks the thread read as well. Actual changes emit thread.updated.

OAuth: allowed with all of `mail:write`, `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.threads.update`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-update) in TypeScript, [`client.threads.update`](https://doorman.fyi/docs/python/reference/mail.md#threads-update) in Python, the [`threads_update`](https://doorman.fyi/docs/mcp/tools/mail.md#threads-update) tool and [`doorman threads update`](https://doorman.fyi/docs/cli/commands/mail.md#threads-update) on the command line.

Organizations: a member's console session needs `mail:write` and `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

**Request body (application/json): UpdateThread**
Changes to the thread's read state, metadata or labels. Omitted fields stay as they are; metadata and labels replace the entire value.
- `isRead` (boolean, optional)
- `metadata` (Metadata, optional)
- `labels` (ThreadLabels, optional)

Answers `200`: The thread as it is now.

**Response 200: Thread**
A conversation: the messages that reply to each other, or share a subject and a participant.
- `id` (string): A thread identifier. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`
- `inboxId` (string): An inbox identifier. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`
- `subject` (string): The subject of the first message. Example: `Invoice 2847`
- `participants` (string[]): Every address seen in the thread other than the inbox's own, sorted. Example: `["sam@example.com"]`
- `messageCount` (integer)
- `isRead` (boolean): False until the thread is marked read or a reply is sent.
- `isSeen` (boolean, optional): Whether a person has looked at the thread in the console since mail last arrived in it. It is the console's own mark and says nothing about `isRead`, which is what an agent polls: a person looking at a thread does not mark it read. Older deployments omit it.
- `metadata` (Metadata, optional)
- `labels` (ThreadLabels, optional)
- `riskLevel` ("low" | "medium" | "high" | "critical" | null, optional): The highest risk level among the thread's inbound messages that the owner has not marked safe; null when none was assessed. Older deployments omit it.
- `firstMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageId` (string | null)
- `createdAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`

Example 200 response:
```json
{
  "id": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "subject": "Invoice 2847",
  "participants": [
    "sam@example.com"
  ],
  "messageCount": 1,
  "isRead": false,
  "metadata": {},
  "labels": [],
  "riskLevel": "low",
  "firstMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageId": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "createdAt": "2026-11-05T10:05:00.000Z"
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | A field is missing or invalid; the message names it. |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X PATCH "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m" \
  -H "authorization: Bearer $DOORMAN_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "isRead": true
  }'
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m", {
  method: "PATCH",
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
    "content-type": "application/json",
  },
  redirect: "manual", credentials: "omit",
  body: JSON.stringify({
    "isRead": true
  }),
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.patch(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    json={
        "isRead": True,
    },
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Trash a thread

`DELETE /v1/threads/{threadId}`

Access `any`: any API key, or a console session.

The thread and its messages leave every list and read, a reply to it answers 404 `thread_not_found`, and a later message in the same conversation starts a new thread. Where the deployment erases, it is erased 30 days later.

OAuth: allowed with all of `mail:write`, `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.threads.trash`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-trash) in TypeScript, [`client.threads.trash`](https://doorman.fyi/docs/python/reference/mail.md#threads-trash) in Python, the [`threads_trash`](https://doorman.fyi/docs/mcp/tools/mail.md#threads-trash) tool and [`doorman threads trash`](https://doorman.fyi/docs/cli/commands/mail.md#threads-trash) on the command line.

Organizations: a member's console session needs `mail:write` and `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

Answers `204`: Trashed.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X DELETE "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m", {
  method: "DELETE",
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
// 204: nothing to read.
```

Python:
```python
import os
import requests

response = requests.delete(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
# 204: nothing to read.
```

## Restore a trashed thread

`POST /v1/threads/{threadId}/restore`

Access `session`: a console session only; an API key gets 403 `session_required`.

Takes a thread back out of the trash: it and its messages return to every list and read, and `thread.updated` says so. A thread that is not in the trash is answered as it is. Mail that was held, discarded or still waits for a scan is in the trash to keep it from agents and is not restored this way (404): only releasing held mail delivers it. A message that arrived in the same conversation while the thread was trashed started a thread of its own, and stays there.

OAuth: not available to delegated app tokens.

Also available as [`client.threads.restore`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-restore) in TypeScript and [`client.threads.restore`](https://doorman.fyi/docs/python/reference/mail.md#threads-restore) in Python.

Organizations: a member's console session needs `mail:write` and `mail:read`. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

Answers `200`: The thread, out of the trash.

**Response 200: Thread**
A conversation: the messages that reply to each other, or share a subject and a participant.
- `id` (string): A thread identifier. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`
- `inboxId` (string): An inbox identifier. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`
- `subject` (string): The subject of the first message. Example: `Invoice 2847`
- `participants` (string[]): Every address seen in the thread other than the inbox's own, sorted. Example: `["sam@example.com"]`
- `messageCount` (integer)
- `isRead` (boolean): False until the thread is marked read or a reply is sent.
- `isSeen` (boolean, optional): Whether a person has looked at the thread in the console since mail last arrived in it. It is the console's own mark and says nothing about `isRead`, which is what an agent polls: a person looking at a thread does not mark it read. Older deployments omit it.
- `metadata` (Metadata, optional)
- `labels` (ThreadLabels, optional)
- `riskLevel` ("low" | "medium" | "high" | "critical" | null, optional): The highest risk level among the thread's inbound messages that the owner has not marked safe; null when none was assessed. Older deployments omit it.
- `firstMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageId` (string | null)
- `createdAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`

Example 200 response:
```json
{
  "id": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "subject": "Invoice 2847",
  "participants": [
    "sam@example.com"
  ],
  "messageCount": 1,
  "isRead": false,
  "metadata": {},
  "labels": [],
  "riskLevel": "low",
  "firstMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageId": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "createdAt": "2026-11-05T10:05:00.000Z"
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `session_required` | Account keys, developer apps, relying parties, installations, consent, approving a sign-in and the assistant require a console session. So does loosening the security policy, trusting a sender, releasing held mail, allowing a sign-in, letting agents sign in to new services alone or telling a service who owns an agent, unless the account allows its account keys to. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X POST "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/restore" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/restore", {
  method: "POST",
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.post(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/restore",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Mark a thread seen

`PUT /v1/threads/{threadId}/seen`

Access `session`: a console session only; an API key gets 403 `session_required`.

Records that a person looked at the thread in the console, or that they want it shown as new again. It moves `isSeen` and nothing else: `isRead`, which agents poll, stays as it is, and no event is emitted. Mail that arrives in the thread clears it.

OAuth: not available to delegated app tokens.

Also available as [`client.threads.seen`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-seen) in TypeScript and [`client.threads.seen`](https://doorman.fyi/docs/python/reference/mail.md#threads-seen) in Python.

Organizations: a member's console session needs `mail:read`. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

**Request body (application/json): SetThreadSeen**
Whether a person has looked at the thread: true once they opened it, false to show it as new again.
- `seen` (boolean)

Answers `200`: The thread as it is now.

**Response 200: Thread**
A conversation: the messages that reply to each other, or share a subject and a participant.
- `id` (string): A thread identifier. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`
- `inboxId` (string): An inbox identifier. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`
- `subject` (string): The subject of the first message. Example: `Invoice 2847`
- `participants` (string[]): Every address seen in the thread other than the inbox's own, sorted. Example: `["sam@example.com"]`
- `messageCount` (integer)
- `isRead` (boolean): False until the thread is marked read or a reply is sent.
- `isSeen` (boolean, optional): Whether a person has looked at the thread in the console since mail last arrived in it. It is the console's own mark and says nothing about `isRead`, which is what an agent polls: a person looking at a thread does not mark it read. Older deployments omit it.
- `metadata` (Metadata, optional)
- `labels` (ThreadLabels, optional)
- `riskLevel` ("low" | "medium" | "high" | "critical" | null, optional): The highest risk level among the thread's inbound messages that the owner has not marked safe; null when none was assessed. Older deployments omit it.
- `firstMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`
- `lastMessageId` (string | null)
- `createdAt` (string (date-time)) Example: `2026-11-05T10:05:00.000Z`

Example 200 response:
```json
{
  "id": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "subject": "Invoice 2847",
  "participants": [
    "sam@example.com"
  ],
  "messageCount": 1,
  "isRead": false,
  "metadata": {},
  "labels": [],
  "riskLevel": "low",
  "firstMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageAt": "2026-11-05T10:05:00.000Z",
  "lastMessageId": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "createdAt": "2026-11-05T10:05:00.000Z"
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | A field is missing or invalid; the message names it. |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `session_required` | Account keys, developer apps, relying parties, installations, consent, approving a sign-in and the assistant require a console session. So does loosening the security policy, trusting a sender, releasing held mail, allowing a sign-in, letting agents sign in to new services alone or telling a service who owns an agent, unless the account allows its account keys to. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X PUT "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/seen" \
  -H "authorization: Bearer $DOORMAN_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "seen": true
  }'
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/seen", {
  method: "PUT",
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
    "content-type": "application/json",
  },
  redirect: "manual", credentials: "omit",
  body: JSON.stringify({
    "seen": true
  }),
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.put(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/seen",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    json={
        "seen": True,
    },
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Read a thread's messages

`GET /v1/threads/{threadId}/messages`

Access `any`: any API key, or a console session.

The thread and its messages in order, oldest first, each with its text, classification and attachments.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.threads.messages`](https://doorman.fyi/docs/sdk/reference/mail.md#threads-messages) in TypeScript, [`client.threads.messages`](https://doorman.fyi/docs/python/reference/mail.md#threads-messages) in Python, the [`threads_messages`](https://doorman.fyi/docs/mcp/tools/mail.md#threads-messages) tool and [`doorman threads messages`](https://doorman.fyi/docs/cli/commands/mail.md#threads-messages) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | `string` | yes | The thread. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`. |

Answers `200`: The thread and its messages.

**Response 200: ThreadMessages**
A thread with its messages in order.
- `thread` (Thread)
- `data` (Message[]): Oldest first, at most 500.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/messages" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/messages", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/threads/thr_01jc5a1b2c3d4e5f6g7h8j9k0m/messages",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## List messages

`GET /v1/inboxes/{inboxId}/messages`

Access `any`: any API key, or a console session.

The inbox's messages across threads, newest first, inbound and outbound alike unless filtered. Messages in trashed threads are left out.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.inboxes.messages.list`](https://doorman.fyi/docs/sdk/reference/mail.md#inboxes-messages-list) in TypeScript, [`client.inboxes.messages.list`](https://doorman.fyi/docs/python/reference/mail.md#inboxes-messages-list) in Python, the [`inboxes_messages_list`](https://doorman.fyi/docs/mcp/tools/mail.md#inboxes-messages-list) tool and [`doorman inboxes messages list`](https://doorman.fyi/docs/cli/commands/mail.md#inboxes-messages-list) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `inboxId` | path | `string` | yes | The inbox. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`. |
| `direction` | query | `"inbound" \| "outbound"` | no | Only received or only sent messages. |
| `limit` | query | `integer` | no | Page size, 1 to 100. Defaults to 50. |
| `offset` | query | `integer` | no | Rows to skip. Defaults to 0. |

Answers `200`: A page of messages.

**Response 200: MessageList**
A page of an inbox's messages, newest first.
- `data` (Message[])
- `limit` (integer): The page size that was applied.
- `offset` (integer): The offset that was applied.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | A field is missing or invalid; the message names it. |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/messages" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/messages", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/messages",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Read a message

`GET /v1/messages/{messageId}`

Access `any`: any API key, or a console session.

One message with its text, headers, classification and attachments.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.messages.get`](https://doorman.fyi/docs/sdk/reference/mail.md#messages-get) in TypeScript, [`client.messages.get`](https://doorman.fyi/docs/python/reference/mail.md#messages-get) in Python, the [`messages_get`](https://doorman.fyi/docs/mcp/tools/mail.md#messages-get) tool and [`doorman messages get`](https://doorman.fyi/docs/cli/commands/mail.md#messages-get) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | `string` | yes | The message. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`. |

Answers `200`: The message.

**Response 200: Message**
One message, inbound or outbound, with its text, headers, classification and attachments.
- `id` (string): A message identifier. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`
- `inboxId` (string): An inbox identifier. Example: `inb_01jc4q7w9k2m5n8p3r6t1v4x7z`
- `threadId` (string): A thread identifier. Example: `thr_01jc5a1b2c3d4e5f6g7h8j9k0m`
- `direction` ("inbound" | "outbound")
- `rfcMessageId` (string | null): The Message-ID header of inbound mail; null for mail this API sent. Example: `<a1b2c3@example.com>`
- `inReplyTo` (string | null): The In-Reply-To header, when the message is a reply.
- `references` (string[]): The References chain, oldest first.
- `from` (NamedAddress)
- `to` (NamedAddress[])
- `cc` (NamedAddress[])
- `bcc` (NamedAddress[]): Only outbound mail carries blind copies.
- `replyTo` (string | null): The Reply-To address, when one was given.
- `deliveryRole` ("to" | "cc" | "bcc" | null): How the inbox received the message: as a to, cc or bcc recipient. Null for outbound mail.
- `subject` (string) Example: `Invoice 2847`
- `text` (string | null): The plain-text body, or text derived from the HTML when there was none.
- `hasHtml` (boolean): Whether an HTML body is stored; read it at /v1/messages/{messageId}/html.
- `rawUrl` (string | null): Where to download the original message/rfc822; null for outbound mail.
- `sizeBytes` (integer)
- `category` ("personal" | "automated" | "marketing" | "bounce" | "spam" | "malicious"): What kind of mail this is; ordinary outbound mail is personal and rule-generated mail is automated.
- `autoReplyable` (boolean): False for anything an agent should not answer on its own.
- `verdict` ("clean" | "unverified" | "suspicious" | null): From the authentication results; null for outbound mail.
- `spamScore` (number | null): How likely the message is junk, from 0 to 1, when it was assessed; null otherwise.
- `authentication` (AuthenticationResults | null)
- `service` (MessageService | null, optional): The outside service the message came from, for the inbox's passport; null for any other mail and for outbound mail. Older deployments omit it.
- `risk` (RiskAssessment | null, optional): Doorman's assessment of an inbound message (ADR-019). Null for outbound mail and for mail that was not assessed. Older deployments omit it.
- `redaction` (Redaction, optional): What the account's healthcare guardrails found in the message (ADR-027), and whether `subject`, `text` and the attachments' `parsedText` carry placeholders in place of it. Absent where no guardrail applies.
- `occurredAt` (string (date-time)): When the message arrived or was sent. Example: `2026-11-05T10:05:00.000Z`
- `attachments` (Attachment[])

Example 200 response:
```json
{
  "id": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "direction": "inbound",
  "rfcMessageId": "<a1b2c3@example.com>",
  "inReplyTo": null,
  "references": [],
  "from": {
    "address": "sam@example.com",
    "name": "Sam Rivera"
  },
  "to": [
    {
      "address": "concierge@doorman.example",
      "name": null
    }
  ],
  "cc": [],
  "bcc": [],
  "replyTo": null,
  "deliveryRole": "to",
  "subject": "Invoice 2847",
  "text": "Hi, invoice 2847 is attached.",
  "hasHtml": true,
  "rawUrl": "https://api.doorman.example/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw",
  "sizeBytes": 48120,
  "category": "personal",
  "autoReplyable": true,
  "verdict": "clean",
  "spamScore": 0.02,
  "authentication": {
    "spf": "pass",
    "dkim": "pass",
    "dmarc": "pass"
  },
  "risk": {
    "score": 6,
    "level": "low",
    "labels": [],
    "reasons": [],
    "sender": {
      "standing": "known",
      "authenticated": true
    },
    "action": "delivered",
    "analysis": "full",
    "review": null
  },
  "occurredAt": "2026-11-05T10:05:00.000Z",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "contentType": "application/pdf",
      "sizeBytes": 45000,
      "url": "https://api.doorman.example/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf",
      "parsedText": "Invoice 2847. Line 3: Setup fee, billed twice. Total 1,480.",
      "extractionMethod": "pdf"
    }
  ]
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Download the original message

`GET /v1/messages/{messageId}/raw`

Access `any`: any API key, or a console session.

The message as it arrived, `message/rfc822`. Outbound messages have no raw copy and answer 404. One with a `malicious` attachment is served to a console session only (403 `risk_blocked` otherwise).

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.messages.raw`](https://doorman.fyi/docs/sdk/reference/mail.md#messages-raw) in TypeScript, [`client.messages.raw`](https://doorman.fyi/docs/python/reference/mail.md#messages-raw) in Python and [`doorman messages raw`](https://doorman.fyi/docs/cli/commands/mail.md#messages-raw) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | `string` | yes | The message. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`. |

Answers `200` as `message/rfc822`: The original message.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `risk_blocked` | The send or the download was refused; `guard` says why: `reply` when the thread holds a flagged message whose sender is not trusted, `recipient` when a recipient is not one the inbox knows, `content` when an attachment did not pass the check of its bytes (`reasons` lists what was found), `guardrail` when a healthcare guardrail found what may not be sent (`entities` lists the kinds). For `reply` and `recipient` a person can send from the console, mark the message safe or trust the sender. For `content`, a program or a file dressed as another kind is refused for every caller; a locked or damaged file, a script, or a document with macros, is refused for keys and app tokens only. A link that delivered harmful software when it was opened in isolation is refused for every caller. |
| 403 | `guardrail_blocked` | A healthcare guardrail keeps this content from keys and apps: the original message, its HTML body or an attachment's bytes carry what the account's guardrails redact, and bytes cannot be redacted. `entities` lists the kinds that were found, never the text. The message's text is available with the findings replaced; a person with `phi:read` reads the original in the console. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw" \
  -H "authorization: Bearer $DOORMAN_API_KEY" \
  -o downloaded.bin
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const bytes = await response.arrayBuffer();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
data = response.content
```

## Read the HTML body

`GET /v1/messages/{messageId}/html`

Access `any`: any API key, or a console session.

The stored HTML body, served as `text/html` under `cache-control: private, no-store`, `x-content-type-options: nosniff` and a content security policy that allows images and inline styles only, under `sandbox`. 404 when the message has no HTML body.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.messages.html`](https://doorman.fyi/docs/sdk/reference/mail.md#messages-html) in TypeScript, [`client.messages.html`](https://doorman.fyi/docs/python/reference/mail.md#messages-html) in Python and [`doorman messages html`](https://doorman.fyi/docs/cli/commands/mail.md#messages-html) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | `string` | yes | The message. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`. |

Answers `200` as `text/html`: The HTML body.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `guardrail_blocked` | A healthcare guardrail keeps this content from keys and apps: the original message, its HTML body or an attachment's bytes carry what the account's guardrails redact, and bytes cannot be redacted. `entities` lists the kinds that were found, never the text. The message's text is available with the findings replaced; a person with `phi:read` reads the original in the console. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/html" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/html", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const text = await response.text();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/html",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
text = response.text
```

## Download an attachment

`GET /v1/attachments/{messageId}/{filename}`

Access `any`: any API key, or a console session.

The attachment's bytes, served with the attachment's own content type as a download. A `malicious` attachment is served to a console session only (403 `risk_blocked` otherwise).

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.attachments.download`](https://doorman.fyi/docs/sdk/reference/mail.md#attachments-download) in TypeScript, [`client.attachments.download`](https://doorman.fyi/docs/python/reference/mail.md#attachments-download) in Python and [`doorman attachments download`](https://doorman.fyi/docs/cli/commands/mail.md#attachments-download) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | `string` | yes | The message. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`. |
| `filename` | path | `string` | yes | The attachment's file name, as the message lists it. Example: `invoice.pdf`. |

Answers `200` as `*/*`: The bytes, with the attachment's content type.

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `risk_blocked` | The send or the download was refused; `guard` says why: `reply` when the thread holds a flagged message whose sender is not trusted, `recipient` when a recipient is not one the inbox knows, `content` when an attachment did not pass the check of its bytes (`reasons` lists what was found), `guardrail` when a healthcare guardrail found what may not be sent (`entities` lists the kinds). For `reply` and `recipient` a person can send from the console, mark the message safe or trust the sender. For `content`, a program or a file dressed as another kind is refused for every caller; a locked or damaged file, a script, or a document with macros, is refused for keys and app tokens only. A link that delivered harmful software when it was opened in isolation is refused for every caller. |
| 403 | `guardrail_blocked` | A healthcare guardrail keeps this content from keys and apps: the original message, its HTML body or an attachment's bytes carry what the account's guardrails redact, and bytes cannot be redacted. `entities` lists the kinds that were found, never the text. The message's text is available with the findings replaced; a person with `phi:read` reads the original in the console. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf" \
  -H "authorization: Bearer $DOORMAN_API_KEY" \
  -o downloaded.bin
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const bytes = await response.arrayBuffer();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
data = response.content
```

## Read an attachment's text

`GET /v1/attachments/{messageId}/{filename}/text`

Access `any`: any API key, or a console session.

The extracted text and how it was obtained, or why it was not.

OAuth: allowed with all of `mail:read`. [App permissions](https://doorman.fyi/docs/oauth.md#scopes) apply in addition to account and resource checks.

Also available as [`client.attachments.text`](https://doorman.fyi/docs/sdk/reference/mail.md#attachments-text) in TypeScript, [`client.attachments.text`](https://doorman.fyi/docs/python/reference/mail.md#attachments-text) in Python, the [`attachments_text`](https://doorman.fyi/docs/mcp/tools/mail.md#attachments-text) tool and [`doorman attachments text`](https://doorman.fyi/docs/cli/commands/mail.md#attachments-text) on the command line.

Organizations: a member's console session needs `mail:read`. API keys and app tokens are not held to member permissions. See [Roles and permissions](https://doorman.fyi/docs/organizations.md#roles).

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | `string` | yes | The message. Example: `msg_01jc5a6g7h8j9k0m1n2p3q4r5s`. |
| `filename` | path | `string` | yes | The attachment's file name, as the message lists it. Example: `invoice.pdf`. |

Answers `200`: The text.

**Response 200: AttachmentText**
The extracted text of an attachment and how it was obtained.
- `filename` (string)
- `contentType` (string)
- `extractionMethod` ("text" | "csv" | "pdf" | "ocr" | "office" | "unsupported" | "skipped" | "skipped_too_large" | "unavailable" | "timeout" | "pdf_error" | "ocr_error" | "office_error" | "html_error")
- `text` (string | null): The text, or null when nothing was extracted; `extractionMethod` says why.

Example 200 response:
```json
{
  "filename": "invoice.pdf",
  "contentType": "application/pdf",
  "extractionMethod": "pdf",
  "text": "Invoice 2847. Total 1,480."
}
```

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 401 | `unauthorized` | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 401 | `session_invalid` | The console session token could not be verified. |
| 401 | `session_expired` | The console session token has expired. |
| 401 | `session_claims_missing` | The session token does not carry a verified email address. |
| 403 | `risk_blocked` | The send or the download was refused; `guard` says why: `reply` when the thread holds a flagged message whose sender is not trusted, `recipient` when a recipient is not one the inbox knows, `content` when an attachment did not pass the check of its bytes (`reasons` lists what was found), `guardrail` when a healthcare guardrail found what may not be sent (`entities` lists the kinds). For `reply` and `recipient` a person can send from the console, mark the message safe or trust the sender. For `content`, a program or a file dressed as another kind is refused for every caller; a locked or damaged file, a script, or a document with macros, is refused for keys and app tokens only. A link that delivered harmful software when it was opened in isolation is refused for every caller. |
| 403 | `insufficient_scope` | The app's token lacks a required scope, or the operation cannot be delegated. |
| 403 | `account_suspended` | The account is suspended. |
| 403 | `account_deleted` | The account was deleted. |
| 403 | `permission_denied` | The signed-in member's role in the organization lacks a permission the operation needs; `permission` names it. An admin of the organization can do it, or change the member's role. |
| 403 | `member_deactivated` | The signed-in person's access to the organization was deactivated, or they were removed from it. It holds from their next request, whatever their session token says. An admin of the organization can let a deactivated member in again. |
| 404 | `not_found` | No such resource for this caller, or no such route. |
| 409 | `account_mismatch` | The request named another account in `x-doorman-account` than the one its credential acts for, as happens when the console's organization was switched in another tab. Reload and try again. |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf/text" \
  -H "authorization: Bearer $DOORMAN_API_KEY"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf/text", {
  headers: {
    authorization: `Bearer ${process.env.DOORMAN_API_KEY}`,
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import os
import requests

response = requests.get(
    "https://api.doorman.fyi/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf/text",
    headers={"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```
