Public API (v1)
Relevant source files
The following files were used as context for generating this wiki page:The Public API (v1) provides mechanisms for external systems to integrate with Inbox Zero. It facilitates both inbound requests to access application data and outbound notifications via webhooks when specific events occur. The primary method for authenticating inbound requests is through user-generated API keys.
The architecture document outlines that v1 endpoints are designed for external integrations. This includes programmatic access to features and receiving automated notifications. The API is discoverable via a self-hosted OpenAPI specification.
Sources: ARCHITECTURE.md
Authentication
Authentication for the public API is handled via API keys. Users can generate these keys within the application settings. Each request to a protected API endpoint must include the API key for validation.
API Key Generation
API keys are created and managed via the /api/user/api-keys endpoint. A user can create a new key by sending a POST request with a name for the key.
The key generation process involves:
- Generating a random, secure key string with a specific prefix (
inboxzero_). - Creating a salted hash of the key using the SHA-256 algorithm.
- Storing the hashed key, along with its name and the associated user ID, in the database.
- Returning the plaintext key to the user. This is the only time the plaintext key is available.
Sources: apps/web/app/api/user/api-keys/route.ts:20-39, apps/web/utils/api-key.ts:8-20
The following diagram illustrates the flow for creating a new API key.
API Key Validation
When a request is made to a protected endpoint, the provided API key is validated. The validateApiKey function handles this process:
- It receives the plaintext API key from the request.
- It queries the database for a user who has an API key with a matching hash.
- If a user and a matching key hash are found, the user's data is returned, authenticating the request.
- The
lastUsedtimestamp for the key is updated in the database.
Sources: apps/web/utils/api-key.ts:22-42
API Specification
The project provides an OpenAPI specification endpoint for API discovery and documentation.
OpenAPI Endpoint
A GET request to /api/v1/openapi returns a JSON object conforming to the OpenAPI 3.0 specification. This is generated dynamically using the @asteasolutions/zod-to-openapi library, which converts Zod schemas into OpenAPI components and paths.
The registry currently defines a path for /api/v1/group-emails, indicating this is one of the available external endpoints.
Sources: apps/web/app/api/v1/openapi/route.ts:7-22
Webhook Notifications
In addition to the request-response API, Inbox Zero can send outbound notifications via webhooks when a rule is triggered. This allows external services to react to events within the user's inbox in real-time.
A webhook is configured as an action on a rule. When the rule's conditions are met, the system sends a POST request to the configured URL.
Webhook Payload
The payload sent to the webhook URL contains information about the email that triggered the rule and details about the rule execution itself.
| Field | Parent | Type | Description |
|---|---|---|---|
threadId | email | string | The Gmail/Outlook thread ID. |
messageId | email | string | The unique message ID. |
subject | email | string | The subject line of the email. |
from | email | string | The sender's email address. |
cc | email | string | Optional CC recipients. |
bcc | email | string | Optional BCC recipients. |
headerMessageId | email | string | The Message-ID header from the email. |
id | executedRule | string | The unique ID for this rule execution. |
ruleId | executedRule | string | The ID of the rule that was triggered. |
reason | executedRule | string | An explanation of why the rule was triggered. |
automated | executedRule | boolean | Indicates if the rule ran automatically. |
createdAt | executedRule | string | The ISO 8601 timestamp of when the rule was executed. |
Sources: apps/web/components/WebhookDocumentation.tsx:47-109
Webhook Authentication
To verify that the request is genuinely from Inbox Zero, each webhook request includes an X-Webhook-Secret header containing the user-configured secret for that webhook.
Sources: apps/web/components/WebhookDocumentation.tsx:111-116
The following diagram shows the webhook notification flow.
Other v1 Endpoints
Reply Tracker
The endpoint /api/v1/reply-tracker exists to disable auto-drafting for reply trackers that have not been used recently. It is a POST endpoint that expects an emailAccountId. However, it is protected by withAuth, which is typically for logged-in user sessions, and is listed in the README.md as a cron job. This suggests it is an internal, scheduled task rather than a public-facing API endpoint for third-party use.
Sources: apps/web/app/api/v1/reply-tracker/route.ts:10-27, README.md