# CLI Source: https://docs.getinboxzero.com/api-reference/cli Use the Inbox Zero API CLI from npm or npx. Use the Inbox Zero API CLI when you want a thin wrapper around the public API for scripts, bots, or local automation. The package is published to npm as `@inbox-zero/api`, and the executable name is `inbox-zero-api`. ## Run with npx Requires Node.js `18+`. ```bash theme={null} npx @inbox-zero/api --help ``` You can also install it globally: ```bash theme={null} npm install -g @inbox-zero/api ``` ## Configure access The CLI reads configuration in this order: 1. Command flags 2. Environment variables 3. `~/.inbox-zero-api/config.json` Supported environment variables: * `INBOX_ZERO_API_KEY` * `INBOX_ZERO_BASE_URL` for self-hosted or custom API deployments Example: ```bash theme={null} inbox-zero-api rules list ``` `base-url` is optional. The CLI defaults to `https://www.getinboxzero.com` and only needs an override for self-hosted or custom deployments. Set `INBOX_ZERO_API_KEY` in your shell or secret manager before running commands. Avoid passing API keys as CLI arguments because they can leak into shell history and process listings. ## Common commands List rules: ```bash theme={null} inbox-zero-api rules list inbox-zero-api rules list --json ``` Get a rule: ```bash theme={null} inbox-zero-api rules get rule_123 --json ``` Create a rule from JSON: ```bash theme={null} inbox-zero-api rules create --file rule.json cat rule.json | inbox-zero-api rules create --file - ``` Update a rule from JSON: ```bash theme={null} cat rule.json | inbox-zero-api rules update rule_123 --file - ``` Delete a rule: ```bash theme={null} inbox-zero-api rules delete rule_123 ``` Read stats: ```bash theme={null} inbox-zero-api stats by-period --period week --json inbox-zero-api stats response-time --json ``` Fetch the live OpenAPI document: ```bash theme={null} inbox-zero-api openapi --json ``` For bots, prefer `--json` so the output is stable and machine-readable. # Delete rule Source: https://docs.getinboxzero.com/api-reference/endpoint/delete-rules-id DELETE /rules/{id} Delete an automation rule for the scoped inbox account. # List rules Source: https://docs.getinboxzero.com/api-reference/endpoint/get-rules GET /rules List automation rules for the scoped inbox account. # Get rule Source: https://docs.getinboxzero.com/api-reference/endpoint/get-rules-id GET /rules/{id} Get a single automation rule for the scoped inbox account. # Get stats by period Source: https://docs.getinboxzero.com/api-reference/endpoint/get-statsby-period GET /stats/by-period Get email statistics grouped by time period. Returns counts of emails by status (all, sent, read, unread, archived, unarchived) for each period. # Get stats response time Source: https://docs.getinboxzero.com/api-reference/endpoint/get-statsresponse-time GET /stats/response-time Get email response time statistics. Returns summary stats, distribution, and trend data showing how quickly you respond to emails. # Create rule Source: https://docs.getinboxzero.com/api-reference/endpoint/post-rules POST /rules Create an automation rule for the scoped inbox account. # Update rule Source: https://docs.getinboxzero.com/api-reference/endpoint/put-rules-id PUT /rules/{id} Replace an automation rule for the scoped inbox account. # Introduction Source: https://docs.getinboxzero.com/api-reference/introduction Use the Inbox Zero API to read inbox statistics and manage automation rules programmatically. If you prefer a CLI wrapper for scripts or bots, see the [API CLI](/api-reference/cli). ## Supported Email Providers Inbox Zero supports integration with: * **Gmail** (Google Workspace and personal accounts) * **Outlook** (Microsoft 365 and personal accounts) ## Getting Started To begin using the Inbox Zero API, you'll need to obtain an API key. Here's how: 1. Log in to your Inbox Zero account 2. Navigate to the [Settings](https://www.getinboxzero.com/settings) page and scroll down to the `API Keys` section 3. Click on the `Create New Secret Key` button 4. Select the permissions (scopes) you need for your key 5. Choose an expiry period Create New Secret Key API keys are scoped to a specific inbox account and only grant access to the permissions you select. Keep your key secure and do not share it publicly. ### Permissions | Scope | Endpoints | | ------------- | ------------------------------------------------------ | | `STATS_READ` | `GET /stats/by-period`, `GET /stats/response-time` | | `RULES_READ` | `GET /rules`, `GET /rules/{id}` | | `RULES_WRITE` | `POST /rules`, `PUT /rules/{id}`, `DELETE /rules/{id}` | A key may include more than one scope. Keys are also bound to one inbox account; they cannot read or change another inbox. ### Self-Hosting If you are self-hosting Inbox Zero, set `NEXT_PUBLIC_EXTERNAL_API_ENABLED=true` and `API_KEY_SALT` before rebuilding the app. Generate the salt with `openssl rand -hex 32`. Use your deployment URL as the base URL for requests (for example, `https://your-domain.com/api/v1`). ## Base URL All API requests should be made to the following base URL: ``` https://www.getinboxzero.com/api/v1 ``` ## Authentication Include your API key in the header of each request: ``` API-Key: YOUR_API_KEY ``` For example: ```bash theme={null} curl "https://www.getinboxzero.com/api/v1/rules" \ -H "API-Key: YOUR_API_KEY" ``` To create a rule: ```bash theme={null} curl -X POST "https://www.getinboxzero.com/api/v1/rules" \ -H "API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ --data '{ "name": "Archive newsletters", "runOnThreads": true, "condition": { "aiInstructions": "Newsletters and recurring promotional emails" }, "actions": [{ "type": "ARCHIVE" }] }' ``` ### Errors API errors are returned as JSON with an `error` message. | Status | Meaning | | ------ | ------------------------------------------------------------------------------------------------------ | | `400` | Invalid query, path, or request body; an action may also be disabled by the deployment's feature flags | | `401` | The `API-Key` header is missing, invalid, or expired | | `403` | The key lacks a required scope or is not account-scoped | | `404` | The requested rule does not exist in the key's inbox account | | `500` | An unexpected server error occurred | The `DELETE` rule action, which moves matching emails to trash, is available only when the deployment enables `NEXT_PUBLIC_DELETE_EMAIL_ACTION_ENABLED`. This feature flag is separate from `DELETE /rules/{id}`, which deletes a rule definition. ## Request New Endpoint If you have a new endpoint that you would like to add to the API, open an issue on [GitHub](https://github.com/elie222/inbox-zero/issues/new). # Contributing Source: https://docs.getinboxzero.com/contributing Set up Inbox Zero for local development This guide is for developers who want to run Inbox Zero locally and contribute to the project.