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

# Send a document message

> Send a document via URL or base64-encoded data. The `filename` field is required. The response contains the message ID.



## OpenAPI

````yaml /openapi/wsapi-api.yaml post /messages/document
openapi: 3.0.3
info:
  title: WSAPI - WhatsApp API
  description: >-
    RESTful HTTP API for WhatsApp via whatsmeow. Supports multi-instance
    connections, connections, webhook event delivery, and HMAC-SHA256 signing.
    Includes self-service instance management endpoints served by the API
    Gateway.
  version: 2.0.0
servers:
  - url: https://api.wsapi.chat
    description: WSAPI API
security:
  - ApiKeyAuth: []
tags:
  - name: Account
    description: >-
      Customer account management — instances, subscriptions, and default
      settings (CustomerApiKey auth)
  - name: Session
    description: WhatsApp session management (login, logout, status)
  - name: Messages
    description: Send and manage WhatsApp messages
  - name: Groups
    description: Group management
  - name: Communities
    description: Community management
  - name: Contacts
    description: Contact lookup and management
  - name: Users
    description: Own account management, user lookup, and profile information
  - name: Media
    description: Media download
  - name: Chats
    description: Chat listing, info, settings, and management
  - name: Calls
    description: Call management
  - name: Newsletters
    description: Newsletter/channel management
  - name: Status
    description: Status/stories posting
paths:
  /messages/document:
    post:
      tags:
        - Messages
      summary: Send a document message
      description: >-
        Send a document via URL or base64-encoded data. The `filename` field is
        required. The response contains the message ID.
      operationId: sendDocument
      parameters:
        - $ref: '#/components/parameters/XInstanceId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendDocumentRequest'
            examples:
              byURL:
                summary: Document by URL with caption
                value:
                  to: 1234567890@s.whatsapp.net
                  url: https://example.com/report.pdf
                  filename: report.pdf
                  caption: Monthly report
              byBase64:
                summary: Document by base64
                value:
                  to: 1234567890@g.us
                  data: JVBERi0xLjQKJeLjz9M...
                  filename: numbers.xlsx
      responses:
        '201':
          $ref: '#/components/responses/Created'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          $ref: '#/components/responses/DeviceNotPaired'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  parameters:
    XInstanceId:
      name: X-Instance-Id
      in: header
      required: true
      description: The ID of the WhatsApp instance to use
      schema:
        type: string
        default: '{{instanceId}}'
  schemas:
    SendDocumentRequest:
      allOf:
        - $ref: '#/components/schemas/SendMediaRequest'
        - type: object
          required:
            - filename
          properties:
            filename:
              type: string
              description: Filename shown to the recipient
    SendMediaRequest:
      type: object
      required:
        - to
      properties:
        to:
          type: string
          description: Recipient JID
        data:
          type: string
          description: Base64-encoded file data (mutually exclusive with `url`)
        url:
          type: string
          format: uri
          description: >-
            URL to download the media from (mutually exclusive with `data`, max
            50 MB)
        mimeType:
          type: string
          description: MIME type of the file (auto-detected if omitted)
        caption:
          type: string
          description: Media caption
        mentions:
          type: array
          items:
            type: string
        replyTo:
          type: string
        replyToSenderId:
          type: string
        isForwarded:
          type: boolean
        viewOnce:
          type: boolean
          description: Send as view-once media
        ephemeralExpiration:
          type: string
          enum:
            - 'off'
            - 24h
            - 7d
            - 90d
    Error:
      type: object
      description: Standard error response returned by all API endpoints
      required:
        - detail
        - status
      properties:
        detail:
          type: string
          description: Human-readable error message
          example: invalid request body
        status:
          type: integer
          description: HTTP status code
          example: 400
  responses:
    Created:
      description: Resource created
      content:
        application/json:
          schema:
            type: object
            properties:
              id:
                type: string
                description: ID of the created resource
          example:
            id: '01234567890123456'
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 400
            detail: invalid request body
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 401
            detail: unauthorized
    DeviceNotPaired:
      description: Device is not paired. Complete the pairing process first.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 403
            detail: device not paired
    ServiceUnavailable:
      description: Instance not available (not connected or service is nil)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            status: 503
            detail: instance not available
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Instance or customer-level API key. Either the instance's own API key or
        the customer's API key is accepted. Must be paired with the
        X-Instance-Id header to identify the target instance.

````