> ## Documentation Index
> Fetch the complete documentation index at: https://pigeonpost-developer.27communication.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a draft

> The fields you send replace the draft's; the rest is kept. The draft is saved again in the
mailbox, so it gets a **new `id`** (the old one no longer works).




## OpenAPI

````yaml /api-reference/openapi.yaml patch /{account_id}/drafts/{draft_id}
openapi: 3.1.0
info:
  title: PigeonPost API
  version: 1.0.0
  description: >
    Connect your users' mailboxes (Gmail with an app password, and any IMAP/SMTP
    provider), read, send and manage their email, and

    receive webhooks when something changes. The API follows Unipile's v2
    conventions (ids, lists,

    events); its own version is v1.


    **Authentication:** every request needs your access token in the `X-API-KEY`
    header. Create

    tokens in your dashboard under **API keys**, or with `POST
    /api/v1/api-keys`.


    **Base URL:** `https://{your DSN}/api/v1`. Your DSN is shown in your
    dashboard.


    **Emails follow Unipile's v2 email API:** the account goes in the path

    (`/api/v1/{account_id}/emails`, `/emails/send`, `/folders`, `/drafts`), with
    separate read,

    unread, modify and thread actions. IMAP only.


    **Ids** carry their type: `acc_…` (account), `email_…`, `att_…`
    (attachment), `fld_…`

    (folder), `drf_…` (draft), `we_…` (webhook endpoint), `evt_…` (event),
    `pk_…` (API key).


    **Lists** are `{ "object": "<Plural>", "data": [...], "has_more": true|false
    }`. Accounts,

    webhook endpoints, conversations and API keys page with `offset` and
    `limit`. Emails, drafts

    and contacts page with a `cursor`: pass the `cursor` of a response back to
    get the next page.


    **Errors** always have the same JSON shape: `status`, `type`, `title`,
    `detail`.
servers:
  - url: https://{dsn}/api/v1
    description: Your workspace's DSN, from your dashboard
    variables:
      dsn:
        default: mail-api.example.com
        description: Your DSN, for example mail-api.example.com
security:
  - apiKey: []
tags:
  - name: Auth
    description: Connect a mailbox from your app (IMAP/SMTP).
  - name: Accounts
    description: The mailboxes connected to your workspace.
  - name: Emails
    description: Read, search, send, change and delete emails.
  - name: Attachments
    description: Download the files attached to an email.
  - name: Drafts
    description: Drafts saved in the user's mailbox.
  - name: Folders
    description: Folders (Gmail labels appear as folders over IMAP).
  - name: Contacts
    description: The people an account has emailed with.
  - name: Webhooks
    description: Get notified when something happens in a mailbox.
  - name: API keys
    description: Access tokens for this API.
paths:
  /{account_id}/drafts/{draft_id}:
    parameters:
      - $ref: '#/components/parameters/account_id'
      - $ref: '#/components/parameters/draft_id'
    patch:
      tags:
        - Drafts
      summary: Update a draft
      description: >
        The fields you send replace the draft's; the rest is kept. The draft is
        saved again in the

        mailbox, so it gets a **new `id`** (the old one no longer works).
      operationId: updateDraft
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendInput'
      responses:
        '200':
          description: Updated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DraftResult'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/InvalidCredentials'
        '404':
          $ref: '#/components/responses/NotFound'
        '502':
          $ref: '#/components/responses/ProviderError'
components:
  parameters:
    account_id:
      name: account_id
      in: path
      required: true
      description: The account's `acc_…` id.
      schema:
        type: string
      example: acc_ba1fa6938d8548298e8ce62e4b4b4e99
    draft_id:
      name: draft_id
      in: path
      required: true
      description: The `drf_…` id from creation, or the synced draft's `email_…` id.
      schema:
        type: string
      example: drf_r-4419383208612875012
  schemas:
    SendInput:
      type: object
      properties:
        to:
          type: array
          items:
            $ref: '#/components/schemas/Recipient'
        cc:
          type: array
          items:
            $ref: '#/components/schemas/Recipient'
        bcc:
          type: array
          items:
            $ref: '#/components/schemas/Recipient'
        reply_to:
          type: array
          items:
            $ref: '#/components/schemas/Recipient'
          description: The Reply-To header's addresses.
        from:
          type: object
          properties:
            display_name:
              type: string
            email:
              type: string
          description: Sender name; `email` can set a send-as alias.
        subject:
          type: string
        html:
          type: string
          description: HTML body.
        plain_text:
          type: string
          description: Plain-text body (made from `html` when left out).
        reply_to_message_id:
          type: string
          description: 'The email you answer: its Message-ID, or its `email_…` id.'
        custom_headers:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              value:
                type: string
          description: >-
            X-…, List-Unsubscribe, List-Unsubscribe-Post, Auto-Submitted (no,
            auto-replied, auto-generated, auto-notified) or Reply-To.
        metadata:
          type: string
          maxLength: 1000
          description: >-
            Your note about this email (never in the email), returned as
            `sent_by.metadata` on its Sent copy.
        tracking_options:
          type: object
          properties:
            opens:
              type: boolean
            links:
              type: boolean
            label:
              type: string
            custom_domain:
              type: string
        attachments:
          type: array
          items:
            type: object
            required:
              - content
            properties:
              filename:
                type: string
              content_type:
                type: string
              content:
                type: string
                contentEncoding: base64
    DraftResult:
      type: object
      properties:
        object:
          type: string
          enum:
            - DraftCreated
            - DraftUpdated
        id:
          type: string
          description: '`drf_…`, the draft''s id.'
        account_id:
          type: string
        draft_id:
          type: string
          description: '`drf_…`'
        previous_draft_id:
          type: string
          description: 'After an update: the old id, which no longer works.'
        message_id:
          type: string
        tracking_id:
          type:
            - string
            - 'null'
    Recipient:
      type: object
      description: A recipient when sending.
      properties:
        email:
          type: string
          format: email
        display_name:
          type: string
      required:
        - email
    Error:
      type: object
      properties:
        status:
          type: integer
        type:
          type: string
          enum:
            - errors/invalid_parameters
            - errors/unauthorized
            - errors/invalid_credentials
            - errors/not_found
            - errors/already_exists
            - errors/provider_rejected
            - errors/provider_error
            - errors/unexpected_error
        title:
          type: string
        detail:
          type: string
  responses:
    BadRequest:
      description: A parameter is missing or wrong. `detail` says which.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 400
            type: errors/invalid_parameters
            title: Invalid parameters
            detail: limit must be between 1 and 250
    InvalidCredentials:
      description: >-
        `errors/invalid_credentials`: the mail provider rejected the account's
        password or token; reconnect it. (`errors/unauthorized`: a bad access
        token.)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 401
            type: errors/invalid_credentials
            title: Invalid credentials
            detail: 'the mail provider rejected the credentials: invalid_grant'
    NotFound:
      description: Nothing with this id (a malformed or wrong-type id is also not found).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 404
            type: errors/not_found
            title: Not found
            detail: email email_94a0d77db739407e932c3b97fef44aac not found
    ProviderError:
      description: The mail provider failed or didn't answer. Try again later.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 502
            type: errors/provider_error
            title: Mail provider error
            detail: timed out talking to imap.example.com
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-KEY
      description: Your access token, from your dashboard under **API keys**.

````

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