# Onbox API and CLI

> The /v1 REST API and the onbox command line: when to use them instead of MCP, how to sign in, the route rules and errors, and every route.

Onbox has three ways in, over the same public tools.
Each REST route and each CLI command calls one tool that the MCP server serves, with the same arguments, results and rules.

## MCP, REST API or CLI

- MCP (https://api.onbox.ing/mcp): your host is an MCP client (Claude, ChatGPT, Codex, Cursor) and a person is in the session. Prefer it when your host has it. The tools are in [Tools](https://www.onbox.ing/docs/agents/tools.md).
- CLI (`onbox`): you run in a shell without the MCP server, or in a script or CI job. Add `--json` to read the results.
- REST API (https://api.onbox.ing/v1): your own code calls Onbox over HTTP, or you generate a client in any language from the [OpenAPI spec](https://api.onbox.ing/api/docs/openapi.json). The same spec has a "Chat for your customers" section for building your own chat, on a website or in a native app, with a visitor token, no team key.

Every call acts as one person, in one organisation, with what their role allows.
For several organisations, use one profile or one key for each.

## Sign in

- OAuth, for a person at a browser: `onbox login`, or `onbox login --device` on a machine without one. The CLI asks for the `read`, `write` and `offline_access` scopes, so it stays signed in.
- Personal API key, for scripts, CI and agents without a browser: the person creates one in Onbox under Settings, API keys. It starts with `onbox_sk_` and is shown once. It can only read unless the person allows changes (`write`), and it may expire. It acts as the person who created it, and stops working once it is revoked or expires, or that person leaves the organisation.
- Scopes: a route whose tool only reads needs `read`; every other route needs `write`. Each route below names its scope. A credential without it gets 403 with the code `insufficient_scope`.
- Over HTTP, send the token or the key as a bearer: `Authorization: Bearer onbox_sk_...`. OAuth discovery: https://api.onbox.ing/.well-known/oauth-authorization-server.

## The CLI

- Run it without installing: `npx @onbox/cli --help`. Or install it: `npm i -g @onbox/cli`, then `onbox --help`. It needs Node 20 or later. Package: https://www.npmjs.com/package/@onbox/cli.
- Sign in: `onbox login` opens the browser and saves a profile named after the organisation. `onbox auth set-key` saves a personal API key as a profile; it reads the key from a hidden prompt or from stdin.
- Without a profile, set `ONBOX_API_KEY` to the key, and `ONBOX_API_URL` for an API other than https://api.onbox.ing. A command uses `--profile <name>` first, then `ONBOX_API_KEY`, then `ONBOX_PROFILE`, then the active profile.
- Commands are generated from the routes below, as `onbox <noun> <verb>`: `onbox conversations list --limit 20`, `onbox drafts send <id>`. A path parameter is a positional argument; the other arguments are flags.
- `onbox <noun>` lists a group's commands. `onbox <noun> <verb> --help` shows its flags, the route it calls and the scope it needs.
- `onbox api <GET|POST|PUT|PATCH|DELETE> <path>` calls any route: `-q key=value` for query parameters, `-d <json|@file|@->` for the body. For example `onbox api GET /v1/conversations -q limit=5`.
- `--limit <n>` returns at most n items and `--all` every item, following pages.

## Output and safety

- API results are generally tables on a terminal.
  Piped, or with `--json`, they are the API's JSON, unchanged apart from paging (`--all` merges the list and keeps the last page's `nextCursor` or `hasMore`).
- With `--json`, errors are `{"error":{"code","message","use?"}}` on stderr.
  `use` names the route to call instead, when the API says so.
- Nothing prompts without a terminal.
- A tool with `destructiveHint` asks for confirmation on a terminal.
  Without one it exits `6` before calling the API, unless `--yes` is given.
- Requests carry `User-Agent: onbox-cli/<version>`.

## Exit codes

| Code | Meaning                                                                                     |
| ---- | ------------------------------------------------------------------------------------------- |
| 0    | Success                                                                                     |
| 1    | The API refused or failed (400, 409, 422, 5xx), or an unexpected error                      |
| 2    | Usage: unknown command or flag, missing or malformed argument                               |
| 3    | Not signed in, or the credential is no longer valid (401)                                   |
| 4    | Forbidden (403), including a token without the scope the route needs (`insufficient_scope`) |
| 5    | Not found (404)                                                                             |
| 6    | A destructive command needs `--yes` and there is no terminal                                |
| 7    | The API could not be reached                                                                |

## The REST API

The base URL is https://api.onbox.ing/v1.
The OpenAPI 3 document is at https://api.onbox.ing/api/docs/openapi.json, with no sign-in.
Its "Chat for your customers" section is for building your own chat, on a website or in a native app: its `/v1/chat/{chatId}/...` routes act for a chat's anonymous visitor with a visitor token, no team key, and are not in the routes below.
The backend generates it from the same route table as the CLI's commands; it gives each route's arguments and the tool's full description.

The routes follow these rules (ADR 0007):

1. One item: its ID is in the path (`GET|PATCH|DELETE /v1/drafts/{draftId}`). A single-item read returns that item, or 404.
2. A conversation's drafts, comments, messages and pending actions can also be reached through it (`GET /v1/conversations/{conversationId}/drafts`).
3. A step that is not create, update or delete is a `POST` on a verb under the item (`POST /v1/drafts/{draftId}/send`).
4. A batch is the same action on the collection, with the IDs in the body (`POST /v1/conversations/move`, `PATCH /v1/conversations`).
5. A batch read is `GET .../get?ids=...` (`GET /v1/conversations/get?ids=a&ids=b`).
6. `GET /v1/conversations` lists, filters and searches. There is no `/search` route.

`GET` and `DELETE` take the other arguments as query parameters: a list is a repeated key, an object a JSON string.
`POST`, `PUT` and `PATCH` take them as a JSON body.
A route that sets an argument itself refuses a request that sends another value for it.

## Errors

An error has a 4xx or 5xx status and a JSON body:

```json
{ "code": "account_not_ready", "message": "...", "use": { "tool": "add_inbox", "method": "POST", "path": "/v1/inboxes" } }
```

- `code`: stable and meant for programs: invalid_request, unauthorized, forbidden, insufficient_scope, not_found, conflict, account_not_ready, tool_error, rate_limited, internal_error.
- `message`: one sentence for the person. Show it to them.
- `use`: there when the message names another tool, with that tool's route. Call it, then try again.

The statuses:

- 400: The arguments are invalid.
- 401: No valid credential.
- 403: The caller may not use this route (an admin-only tool, or a token without the scope the route needs: code insufficient_scope).
- 404: The thing the arguments name does not exist, or the caller cannot see it.
- 409: The account is not ready for this call; the message names the step.
- 422: The tool understood the request and refused it; the message says why.
- 500: Unexpected error.

## Routes

100 routes, read from the OpenAPI document.
A `destructive` route deletes, discards, overwrites or sends: the CLI asks first, or needs `--yes` without a terminal.

### /v1/account

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/account/status` | Get Account Status | read | `get_account_status` |
| `GET /v1/account/billing` | Get Billing | read | `get_billing` |

### /v1/organisation

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `PATCH /v1/organisation` | Update the Organisation | write, destructive | `update_organisation` |

### /v1/support

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `POST /v1/support/requests` | Contact Onbox Support | write, destructive | `contact_onbox_support` |

### /v1/me

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/me/inbox` | My Inbox | read | `list_my_inbox` |

### /v1/conversations

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/conversations` | Search Conversations | read | `search_conversations` |
| `PATCH /v1/conversations` | Update Conversations | write, destructive | `update_conversations` |
| `GET /v1/conversations/get` | Read Conversation History | read | `get_conversations` |
| `GET /v1/conversations/{conversationId}` | Read a Conversation's History | read | `get_conversations` |
| `PATCH /v1/conversations/{conversationId}` | Update Conversations | write, destructive | `update_conversations` |
| `GET /v1/conversations/{conversationId}/drafts` | List a Conversation's Drafts | read | `get_conversations` |
| `POST /v1/conversations/{conversationId}/drafts` | Draft a Reply | write | `create_draft` |
| `GET /v1/conversations/{conversationId}/messages` | List a Conversation's Messages | read | `get_conversations` |
| `GET /v1/conversations/{conversationId}/comments` | List a Conversation's Comments | read | `get_conversations` |
| `POST /v1/conversations/{conversationId}/comments` | Add Comment | write | `create_comment` |
| `GET /v1/conversations/{conversationId}/pending-actions` | List a Conversation's Pending Actions | read | `get_conversations` |
| `POST /v1/conversations/move` | Move Conversations | write, destructive | `move_conversations` |
| `POST /v1/conversations/{conversationId}/move` | Move Conversations | write, destructive | `move_conversations` |
| `POST /v1/conversations/delegate` | Delegate to Onbox | write, destructive | `delegate_conversations` |
| `POST /v1/conversations/{conversationId}/delegate` | Delegate to Onbox | write, destructive | `delegate_conversations` |
| `PATCH /v1/conversations/{conversationId}/tags` | Tag a Conversation's Messages | write, destructive | `tag_messages` |

### /v1/messages

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/messages` | Search Messages | read | `search_messages` |
| `GET /v1/messages/get` | Read Messages | read | `get_messages` |
| `GET /v1/messages/{messageId}` | Read Messages | read | `get_messages` |
| `POST /v1/messages/{messageId}/replies` | Send Message | write, destructive | `send_message` |
| `PATCH /v1/messages/tags` | Tag Messages | write, destructive | `tag_messages` |
| `PATCH /v1/messages/{messageId}/tags` | Tag Messages | write, destructive | `tag_messages` |

### /v1/attachments

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/attachments/{attachmentId}` | Read Attachment | read | `read_attachment` |

### /v1/drafts

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/drafts/{draftId}` | Read Draft | read | `get_draft` |
| `PATCH /v1/drafts/{draftId}` | Edit Draft | write, destructive | `update_draft` |
| `DELETE /v1/drafts/{draftId}` | Discard Draft | write, destructive | `discard_draft` |
| `POST /v1/drafts` | Draft an Email | write | `create_draft` |
| `POST /v1/drafts/{draftId}/send` | Send Draft | write, destructive | `send_draft` |

### /v1/comments

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `POST /v1/comments` | Add Comment | write | `create_comment` |
| `GET /v1/comments/get` | Read Comments | read | `get_comments` |
| `GET /v1/comments/{commentId}` | Read Comments | read | `get_comments` |
| `PATCH /v1/comments/{commentId}` | Edit Comment | write, destructive | `update_comment` |
| `DELETE /v1/comments/{commentId}` | Delete Comment | write, destructive | `delete_comment` |
| `POST /v1/comments/{commentId}/restore` | Restore Comment | write | `restore_comment` |

### /v1/agent-runs

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/agent-runs/{agentRunId}/trace` | Read Agent Run Trace | read | `get_agent_run_trace` |

### /v1/pending-actions

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/pending-actions/get` | Read Pending Actions | read | `get_pending_actions` |
| `GET /v1/pending-actions/{pendingActionId}` | Read Pending Actions | read | `get_pending_actions` |
| `PATCH /v1/pending-actions/{pendingActionId}` | Edit Pending Action | write, destructive | `update_pending_action` |
| `POST /v1/pending-actions/approve` | Approve Pending Actions | write, destructive | `approve_pending_actions` |
| `POST /v1/pending-actions/{pendingActionId}/approve` | Approve Pending Actions | write, destructive | `approve_pending_actions` |
| `POST /v1/pending-actions/discard` | Discard Pending Actions | write, destructive | `discard_pending_actions` |
| `POST /v1/pending-actions/{pendingActionId}/discard` | Discard Pending Actions | write, destructive | `discard_pending_actions` |

### /v1/tags

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/tags` | List Tags | read | `list_tags` |
| `POST /v1/tags` | Create Tag | write | `create_tag` |
| `PATCH /v1/tags/{tagId}` | Edit Tag | write, destructive | `update_tag` |
| `DELETE /v1/tags/{tagId}` | Delete Tag | write, destructive | `delete_tag` |

### /v1/inboxes

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/inboxes` | List Inboxes | read | `list_inboxes` |
| `POST /v1/inboxes` | Add an Inbox | write | `add_inbox` |
| `PATCH /v1/inboxes/{inboxId}` | Update an Inbox | write, destructive | `update_inbox` |
| `DELETE /v1/inboxes/{inboxId}` | Remove an Inbox | write, destructive | `remove_inbox` |

### /v1/members

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/members` | List Team Members | read | `list_members` |
| `PATCH /v1/members/{userId}` | Update Team Member | write, destructive | `update_member` |
| `DELETE /v1/members/{userId}` | Remove Team Member | write, destructive | `remove_member` |

### /v1/invitations

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `DELETE /v1/invitations/{invitationId}` | Revoke an Invitation | write, destructive | `remove_member` |
| `POST /v1/invitations` | Invite Team Members | write, destructive | `invite_members` |

### /v1/integrations

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/integrations` | List Integrations | read | `list_integrations` |
| `POST /v1/integrations` | Add a Custom Integration | write | `create_custom_integration` |
| `GET /v1/integrations/{integration}` | Get an Integration | read | `list_integrations` |
| `PATCH /v1/integrations/{integration}` | Update an Integration | write, destructive | `update_integration` |
| `DELETE /v1/integrations/{integration}` | Disconnect Integration | write, destructive | `disconnect_integration` |
| `POST /v1/integrations/preview` | Preview a Custom Integration | read | `preview_custom_integration` |
| `POST /v1/integrations/{slug}/connect` | Connect a Tool | write, destructive | `connect_integration` |
| `POST /v1/integrations/{integration}/test` | Test an Integration | write | `test_integration` |

### /v1/brain

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `POST /v1/brain/build` | Build the Brain | write, destructive | `build_brain` |
| `GET /v1/brain/{scope}/files` | List Brain Files | read | `list_brain_files` |
| `GET /v1/brain/{scope}/files/get` | Read Brain Files | read | `read_brain_files` |
| `GET /v1/brain/{scope}/files/{path}` | Read Brain Files | read | `read_brain_files` |
| `POST /v1/brain/{scope}/changes` | Write Brain Files | write, destructive | `write_brain_files` |
| `GET /v1/brain/proposals` | List Brain Proposals | read | `list_brain_proposals` |
| `GET /v1/brain/proposals/{proposalId}` | Get a Brain Proposal | read | `list_brain_proposals` |
| `POST /v1/brain/proposals/accept` | Accept Brain Proposals | write, destructive | `accept_brain_proposals` |
| `POST /v1/brain/proposals/{proposalId}/accept` | Accept Brain Proposals | write, destructive | `accept_brain_proposals` |
| `POST /v1/brain/proposals/decline` | Decline Brain Proposals | write, destructive | `decline_brain_proposals` |
| `POST /v1/brain/proposals/{proposalId}/decline` | Decline Brain Proposals | write, destructive | `decline_brain_proposals` |
| `GET /v1/brain/gaps` | List Brain Gaps | read | `list_brain_gaps` |
| `POST /v1/brain/gaps` | Create a Brain Gap | write | `create_brain_gap` |
| `GET /v1/brain/gaps/{gapId}` | Get a Brain Gap | read | `list_brain_gaps` |
| `PATCH /v1/brain/gaps/{gapId}` | Update a Brain Gap | write, destructive | `update_brain_gap` |
| `POST /v1/brain/gaps/{gapId}/conversations` | Record Conversations Under a Brain Gap | write | `record_brain_gap_conversations` |

### /v1/tests

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/tests` | List Tests | read | `list_tests` |
| `POST /v1/tests` | Create Test | write | `create_test` |
| `PATCH /v1/tests/{testId}` | Edit Test | write, destructive | `update_test` |
| `DELETE /v1/tests/{testId}` | Delete Test | write, destructive | `delete_test` |
| `POST /v1/tests/run` | Run Tests | write | `run_tests` |
| `POST /v1/tests/{testId}/run` | Run Tests | write | `run_tests` |
| `GET /v1/tests/results` | Read Test Results | read | `get_test_results` |
| `GET /v1/tests/{testId}/results` | Read a Test's Results | read | `get_test_results` |

### /v1/calendar

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `PUT /v1/calendar/invitations/{eventId}/response` | Respond to an Invitation | write, destructive | `respond_to_invitation` |

### /v1/webhook-endpoints

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/webhook-endpoints` | List Webhook Endpoints | read | `list_webhook_endpoints` |
| `POST /v1/webhook-endpoints` | Create a Webhook Endpoint | write | `create_webhook_endpoint` |
| `PATCH /v1/webhook-endpoints/{endpoint}` | Update a Webhook Endpoint | write, destructive | `update_webhook_endpoint` |
| `DELETE /v1/webhook-endpoints/{endpoint}` | Delete a Webhook Endpoint | write, destructive | `delete_webhook_endpoint` |
| `GET /v1/webhook-endpoints/{endpoint}/deliveries` | List Webhook Deliveries | read | `list_webhook_deliveries` |

### /v1/webhook-events

| Route | What it does | Scope | Tool |
| --- | --- | --- | --- |
| `GET /v1/webhook-events/get` | Get Webhook Events | read | `get_webhook_events` |
| `GET /v1/webhook-events/{eventId}` | Get Webhook Events | read | `get_webhook_events` |
