---
title: "Subscribe a pipeline to a mailbox"
method: POST
path: "/api/v1/pipelines/{pipelineId}/email-subscriptions"
tags: ["Pipelines"]
---

# Subscribe a pipeline to a mailbox

`POST /api/v1/pipelines/{pipelineId}/email-subscriptions`

## Request

- Base URL: `https://app.khotan.com`
- URL: `https://app.khotan.com/api/v1/pipelines/{pipelineId}/email-subscriptions`
- Auth: one of:
  - HTTP bearer
  - API key in header `x-api-key`

Subscribes this pipeline to a connected Gmail or Outlook mailbox so the provider delivers new-message notifications directly to deliveryUrl (https). Gmail: Khotan registers the mailbox watch and a Pub/Sub push subscription whose pushes carry a Google OIDC token. Outlook: Khotan creates a Microsoft Graph subscription — Graph first validates deliveryUrl by POSTing a validationToken query parameter that the receiver must echo as text/plain within 10 seconds, and every later notification carries the clientState returned here. Secret-bearing and never cached; recover a lost clientState from the client-state endpoint.

## Path parameters

- `pipelineId` string, required

## Request body

- object
  - `emailIntegrationId` string, required
  - `deliveryUrl` string, uri, required

## Response `201`

The created subscription. For Outlook it includes the clientState secret.

- object
  - `id` string, required
  - `emailIntegrationId` string, required
  - `provider` 'google' | 'microsoft', required
  - `target` object, required
    - `type` 'app' | 'pipeline', required
    - `id` string, required
  - `deliveryUrl` string, required
  - `status` 'pending' | 'active' | 'failed' | 'disabled', required
  - `expiresAt` string, nullable, required
  - `failure` object, nullable, required
    - `code` string, required
    - `message` string, required
  - `createdAt` string, required
  - `updatedAt` string, required
  - `clientState` string, nullable, required

## Other responses

- `400`: The request was malformed or failed validation.
- `401`: Authentication is missing or invalid.
- `404`: The resource was not found.
- `409`: Response.
- `429`: Too many requests; retry after the indicated delay.
- `502`: Response.

---

[API](https://skmtc.dev/khotan/apis/khotan-api.md) - [All operations](https://skmtc.dev/khotan/apis/khotan-api/llms.txt) - [OpenAPI document](https://skmtc.dev/khotan/apis/khotan-api/revisions/90b512a53e42?raw)
