> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tetherai.ca/llms.txt
> Use this file to discover all available pages before exploring further.

# Handle email OAuth callback

> Provider redirect target. Exchanges the authorization `code` for tokens, persists or refreshes the `EmailAccount`, sets up mailbox watch (Gmail Pub/Sub or Outlook Graph subscription) when configured, then **302-redirects** to the client settings page with `?provider=<name>&status=success|error`. This route is public (no bearer auth) — the userId/organizationId come from the signed OAuth `state`. Only the pre-redirect validation failures surface as JSON (400). On a downstream failure the user is still 302-redirected back to the settings page with `status=error`.



## OpenAPI

````yaml /api-reference/openapi.yaml get /api/email/oauth/callback
openapi: 3.0.3
info:
  title: Tether Relay and Tether API
  version: 1.0.0
  description: >-
    Route-derived OpenAPI contract generated from tether-relay backend sources.
    Regenerate with scripts/sync-openapi-from-backend.mjs.
servers:
  - url: https://your-instance.example.com
    description: Production
  - url: http://localhost:2212
    description: Local API service
security: []
tags:
  - name: AI
  - name: Applications
  - name: Approval
  - name: Auth
  - name: Automations
  - name: Calls
  - name: Campaigns
  - name: Contact Analytics
  - name: Contact Metrics
  - name: Contact Notes
  - name: Contacts
  - name: Conversation Monitor
  - name: Conversations
  - name: Departments
  - name: Email
  - name: Escalation Dashboard
  - name: Event Logs
  - name: Google Sheets
  - name: Marketplace
  - name: Messages
  - name: Notification Sounds
  - name: Notifications
  - name: Org Snapshots
  - name: Organizations
  - name: Outreach
  - name: Outreach Metrics
  - name: Outreach Sources
  - name: Pipelines
  - name: Processes
  - name: Prompts
  - name: Reminders
  - name: Sms
  - name: Templates
  - name: Traces
  - name: Training
  - name: Upload
  - name: User Snapshots
  - name: Users
  - name: Vertical
  - name: Webchats
  - name: Webhook
paths:
  /api/email/oauth/callback:
    get:
      tags:
        - Email
      summary: Handle email OAuth callback
      description: >-
        Provider redirect target. Exchanges the authorization `code` for tokens,
        persists or refreshes the `EmailAccount`, sets up mailbox watch (Gmail
        Pub/Sub or Outlook Graph subscription) when configured, then
        **302-redirects** to the client settings page with
        `?provider=<name>&status=success|error`. This route is public (no bearer
        auth) — the userId/organizationId come from the signed OAuth `state`.
        Only the pre-redirect validation failures surface as JSON (400). On a
        downstream failure the user is still 302-redirected back to the settings
        page with `status=error`.
      operationId: get_email_oauth_callback
      parameters:
        - in: query
          name: code
          required: false
          schema:
            type: string
          description: Authorization code returned by the provider.
        - in: query
          name: state
          required: false
          schema:
            type: string
          description: >-
            Base64-encoded JSON `{ userId, organizationId, provider }` echoed
            back by the provider.
      responses:
        '302':
          description: >-
            Redirect to `${CLIENT_URL}/settings?provider=<name>&status=success`
            on success, or `${CLIENT_URL}/settings?status=error` on failure.
            Frontends should observe the `provider` and `status` query
            parameters on the resulting settings page to surface the outcome to
            the user.
          headers:
            Location:
              description: Client settings URL with provider and status query parameters.
              schema:
                type: string
                format: uri
        '400':
          description: Missing code or state, or invalid state payload
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EmailOAuthCallbackErrorResponse'
components:
  schemas:
    EmailOAuthCallbackErrorResponse:
      type: object
      description: >-
        Error envelope returned by `GET /api/email/oauth/callback` only on the
        pre-redirect validation failures (missing/invalid `code` or `state`).
        Downstream provider exchange failures redirect with `status=error`
        instead of returning JSON.
      properties:
        message:
          type: string
        error:
          type: string
      additionalProperties: true
      example:
        message: Missing code or state
        error: bad_request

````