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

# Connect a Gmail inbox

> Links the caller’s Gmail account. Replaying the same Idempotency-Key returns the same mailbox. When Gmail is already active, redirectUrl is null and the mailbox is usable immediately.



## OpenAPI

````yaml /api-reference/mobilerun-mailbox.yaml post /mailboxes/connections
openapi: 3.1.0
info:
  title: Mobilerun Mailbox
  version: v1
servers:
  - description: Droidrun Cloud API
    url: https://api.mobilerun.ai/v1
security:
  - bearerAuth: []
paths:
  /mailboxes/connections:
    post:
      tags:
        - Mailboxes
      summary: Connect a Gmail inbox
      description: >-
        Links the caller’s Gmail account. Replaying the same Idempotency-Key
        returns the same mailbox. When Gmail is already active, redirectUrl is
        null and the mailbox is usable immediately.
      operationId: createMailboxConnection
      parameters:
        - description: >-
            Idempotency-Key: 1-255 printable ASCII characters. Same key with a
            different request body is a 422 idempotency_key_reused. A retryable
            in-flight duplicate is a 409 with Retry-After and x-should-retry:
            true; a terminal duplicate is a 409 with x-should-retry: false. A
            replay returns the current resource state with Idempotent-Replayed:
            true.
          in: header
          name: idempotency-key
          required: false
          schema:
            description: >-
              Idempotency-Key: 1-255 printable ASCII characters. Same key with a
              different request body is a 422 idempotency_key_reused. A
              retryable in-flight duplicate is a 409 with Retry-After and
              x-should-retry: true; a terminal duplicate is a 409 with
              x-should-retry: false. A replay returns the current resource state
              with Idempotent-Replayed: true.
            example: b3f6a9f0-6f1a-4e9a-9e7a-9c9b6b6a5a3f
            maxLength: 255
            minLength: 1
            pattern: ^[\x21-\x7E]{1,255}$
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMailboxConnectionRequest'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxConnection'
          description: Gmail mailbox link
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxErrorResponse'
          description: The Idempotency-Key header is malformed
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
          description: Unauthorized
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxErrorBody'
          description: Gmail already connected, or the mailbox backend rejected the request
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxErrorResponse'
          description: The Idempotency-Key was reused with a different request
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxErrorBody'
          description: Mailbox backend rate limited
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
          description: Internal Server Error
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MailboxErrorBody'
          description: Mailboxes disabled or temporarily unavailable
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Mobilerun from '@mobilerun/sdk';


            const client = new Mobilerun({
              apiKey: process.env['MOBILERUN_CLOUD_API_KEY'], // This is the default and can be omitted
            });


            const connection = await client.mailboxes.connections.create({
            provider: 'gmail' });


            console.log(connection.address);
        - lang: Python
          source: |-
            import os
            from mobilerun_sdk import Mobilerun

            client = Mobilerun(
                api_key=os.environ.get("MOBILERUN_CLOUD_API_KEY"),  # This is the default and can be omitted
            )
            connection = client.mailboxes.connections.create(
                provider="gmail",
            )
            print(connection.address)
components:
  schemas:
    CreateMailboxConnectionRequest:
      properties:
        bindingHash:
          description: sha256 hex of the browser-held connect binding secret.
          pattern: ^[0-9a-f]{64}$
          type: string
        label:
          maxLength: 100
          type: string
        provider:
          enum:
            - gmail
          type: string
      required:
        - provider
      type: object
    MailboxConnection:
      properties:
        address:
          type:
            - string
            - 'null'
        connectionId:
          format: uuid
          type: string
        mailboxId:
          format: uuid
          type: string
        redirectUrl:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/MailboxConnectionStatus'
      required:
        - connectionId
        - mailboxId
        - redirectUrl
        - status
        - address
      type: object
    MailboxErrorResponse:
      anyOf:
        - $ref: '#/components/schemas/MailboxErrorBody'
        - $ref: '#/components/schemas/MailboxApiErrorEnvelope'
    ApiErrorEnvelope:
      properties:
        code:
          type: string
        details: {}
        message:
          type: string
        retryAfterSeconds:
          type: number
        traceId:
          type: string
      required:
        - code
        - message
      type: object
    MailboxErrorBody:
      properties:
        code:
          $ref: '#/components/schemas/MailboxErrorReason'
        message:
          type: string
      required:
        - code
        - message
      type: object
    MailboxConnectionStatus:
      enum:
        - pending
        - active
        - expired
        - removed
      type: string
    MailboxApiErrorEnvelope:
      properties:
        code:
          $ref: '#/components/schemas/MailboxErrorReason'
        message:
          type: string
        retryAfterSeconds:
          type: number
        traceId:
          type: string
      required:
        - code
        - message
      type: object
    MailboxErrorReason:
      description: >-
        Stable, machine-readable error reason. Values are frozen and never
        renamed; new values may be added, so treat unknown values as a generic
        failure of the same HTTP status.
      enum:
        - mailboxes_disabled
        - otp_extraction_disabled
        - idempotency_conflict
        - invalid_idempotency_key
        - idempotency_key_required
        - idempotency_key_reused
        - invalid_local_part
        - local_part_reserved
        - local_part_taken
        - mailbox_vanity_disabled
        - allocated_mailbox_limit_reached
        - awaiting_payment_limit_reached
        - vanity_awaiting_payment_limit_reached
        - daily_allocation_limit_reached
        - billing_not_configured
        - included_capacity_unavailable
        - mailbox_not_active
        - uncancel_not_allowed
        - backend_rate_limited
        - backend_rejected
        - backend_unavailable
        - assistant_checkout_return_unavailable
        - custom_domains_disabled
        - domain_not_disableable
        - invalid_domain
        - domain_reserved
        - domain_unavailable
        - domain_not_active
        - domain_limit_reached
        - domain_verification_expired
        - domain_claim_superseded
        - dns_check_rate_limited
        - gmail_already_connected
        - connection_pending
        - connection_expired
        - connection_removed
        - message_too_large
        - external_cancel_not_allowed
      type: string
  securitySchemes:
    bearerAuth:
      bearerFormat: Opaque
      description: Bearer token via Authorization header
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.