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

# Add an attachment

> Add an attachment to a draft message. You can send either a multipart/form-data request with the raw file content, or a JSON request with a file ID.



## OpenAPI

````yaml POST /inbox_messages/{inbox_message_id}/attachments
openapi: 3.1.0
info:
  title: Moonbase REST API
  version: v0
servers:
  - url: https://api.moonbase.ai/v0
security:
  - bearer: []
tags:
  - name: Inboxes
    description: Manage your inboxes, conversations, and messages
  - name: Collections
    description: Manage your collections and items
  - name: Marketing
    description: Manage your marketing campaigns and forms
  - name: Activities
    description: View activities and capture calls
  - name: Library
    description: Manage your meetings, files, and notes
paths:
  /inbox_messages/{inbox_message_id}/attachments:
    post:
      tags:
        - Inboxes
      summary: Add an attachment
      description: >-
        Add an attachment to a draft message. You can send either a
        multipart/form-data request with the raw file content, or a JSON request
        with a file ID.
      parameters:
        - name: inbox_message_id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the Message.
          explode: true
      requestBody:
        description: ''
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/MessageAttachmentCreateParams'
          application/json:
            schema:
              $ref: '#/components/schemas/MessageAttachmentCreateParams'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageAttachment'
              examples:
                Attachment already exists:
                  summary: Attachment already exists
                  value:
                    id: 1CLJt2vAY2dWSPDQt8AQpz
                    type: message_attachment
                    filename: readme.txt
                    size: 24
                    download_url: >-
                      https://api.moonbase.ai/asset_redirects/1CLJt2vAY2dWSPDQt8AQpz?token=eyJfcmFpbHMiOnsiZGF0YSI6eyJpZCI6IjFDTEp0MnZBWTJkV1NQRFF0OEFRcHoiLCJibG9iX2lkIjoiMUNMSnQydkFIZVJ0WGZqNEJxNXBpRCIsImNyZWF0ZWRfYXQiOiIyMDI1LTAyLTE3VDE2OjAwOjAwLjAwMFoiLCJuYW1lIjoiYXR0YWNobWVudHMiLCJyZWNvcmRfaWQiOiIxQ0xKdDJ2NWFOZDhHNVNHekVhZVZVIiwicmVjb3JkX3R5cGUiOiJNZXNzYWdlIn0sImV4cCI6IjIwMjUtMDItMTdUMTc6MDA6MDAuMDAwWiIsInB1ciI6InJlZGlyZWN0In19--5d7d52ce87afcd22c2dd88a5a6b1c2822764b32b
                    created_at: '2025-02-17T16:00:00.000Z'
        '201':
          description: Attachment added.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageAttachment'
              examples:
                Add an attachment:
                  summary: Add an attachment
                  value:
                    id: 1CLJt2vAY2dWSPDQt8AQpz
                    type: message_attachment
                    filename: readme.txt
                    size: 24
                    download_url: >-
                      https://api.moonbase.ai/asset_redirects/1CLJt2vAY2dWSPDQt8AQpz?token=eyJfcmFpbHMiOnsiZGF0YSI6eyJpZCI6IjFDTEp0MnZBWTJkV1NQRFF0OEFRcHoiLCJibG9iX2lkIjoiMUNMSnQydkFIZVJ0WGZqNEJxNXBpRCIsImNyZWF0ZWRfYXQiOiIyMDI1LTAyLTE3VDE2OjAwOjAwLjAwMFoiLCJuYW1lIjoiYXR0YWNobWVudHMiLCJyZWNvcmRfaWQiOiIxQ0xKdDJ2NWFOZDhHNVNHekVhZVZVIiwicmVjb3JkX3R5cGUiOiJNZXNzYWdlIn0sImV4cCI6IjIwMjUtMDItMTdUMTc6MDA6MDAuMDAwWiIsInB1ciI6InJlZGlyZWN0In19--5d7d52ce87afcd22c2dd88a5a6b1c2822764b32b
                    created_at: '2025-02-17T16:00:00.000Z'
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Missing file parameter:
                  summary: Missing file parameter
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '400'
                        title: Bad Request
                        detail: >-
                          Provide either a 'file' (binary upload) or 'file_id'
                          (library file ID).
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '401'
                        title: Unauthorized
                        detail: >-
                          Invalid or missing API key or JWT. You should provide
                          your Moonbase API Key or JWT in the authorization
                          header, in the format: "Authorization: Bearer
                          MOONBASE_API_KEY"
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '403'
                        title: Forbidden
        '404':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Message not found:
                  summary: Message not found
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '404'
                        title: Not Found
        '422':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Not a draft:
                  summary: Not a draft
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '422'
                        title: Unprocessable Entity
                        detail: Attachments can only be managed on draft messages.
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '429'
                        title: Too Many Requests
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '500'
                        title: Internal Server Error
        '503':
          description: Service Unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '503'
                        title: Service Unavailable
                        detail: >-
                          The service is temporarily unavailable, please try
                          again later.
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import fs from 'fs';

            import Moonbase from '@moonbaseai/sdk';


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


            const messageAttachment = await
            client.inboxMessages.attachments.create('inbox_message_id');


            console.log(messageAttachment.id);
        - lang: Python
          source: |-
            import os
            from moonbase import Moonbase

            client = Moonbase(
                api_key=os.environ.get("MOONBASE_API_KEY"),  # This is the default and can be omitted
            )
            message_attachment = client.inbox_messages.attachments.create(
                inbox_message_id="inbox_message_id",
            )
            print(message_attachment.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/moonbaseai/moonbase-sdk-go\"\n\t\"github.com/moonbaseai/moonbase-sdk-go/option\"\n)\n\nfunc main() {\n\tclient := moonbase.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tmessageAttachment, err := client.InboxMessages.Attachments.New(\n\t\tcontext.TODO(),\n\t\t\"inbox_message_id\",\n\t\tmoonbase.InboxMessageAttachmentNewParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", messageAttachment.ID)\n}\n"
        - lang: Ruby
          source: >-
            require "moonbase"


            moonbase = Moonbase::Client.new(api_key: "My API Key")


            message_attachment =
            moonbase.inbox_messages.attachments.create("inbox_message_id")


            puts(message_attachment)
components:
  schemas:
    MessageAttachmentCreateParams:
      title: MessageAttachmentCreateParams
      description: ''
      type: object
      properties:
        file:
          type: string
          format: binary
        file_id:
          type: string
      required: []
    MessageAttachment:
      title: MessageAttachment
      description: >-
        The Attachment object represents a file attached to a message. You can
        download the file content via the `download_url`.
      type: object
      properties:
        type:
          description: >-
            String representing the object’s type. Always `message_attachment`
            for this object.
          type: string
          const: message_attachment
        id:
          description: Unique identifier for the object.
          type: string
        filename:
          description: The original name of the uploaded file, including its extension.
          type: string
        size:
          description: The size of the file in bytes.
          type: integer
        download_url:
          description: >-
            A temporary, signed URL to download the file content. The URL
            expires after one hour.
          type: string
          format: uri
        created_at:
          description: >-
            Time at which the object was created, as an ISO 8601 timestamp in
            UTC.
          type: string
          format: date-time
      required:
        - type
        - id
        - filename
        - size
        - download_url
        - created_at
    Errors:
      title: Errors
      description: >-
        The Errors object is a container that holds multiple Error objects when
        an API request encounters several validation or processing issues. This
        allows the API to return comprehensive feedback about all problems
        encountered in a single response.
      type: object
      properties:
        type:
          type: string
          const: errors
        errors:
          description: A list of `Error` objects.
          type: array
          items:
            $ref: '#/components/schemas/Error'
      required:
        - type
    Error:
      title: Error
      description: >-
        The Error object represents a single error that occurred during API
        request processing. It provides detailed information about what went
        wrong, including a unique identifier, status code, and human-readable
        descriptions to help developers understand and resolve the issue.
      type: object
      properties:
        type:
          type: string
          const: error
        id:
          description: A unique identifier for this specific error instance.
          type: string
        status:
          description: The HTTP status code for this problem, as a string.
          type: string
        code:
          description: An application-specific error code string.
          type: string
        title:
          description: A short, human-readable summary of the problem.
          type: string
        detail:
          description: A human-readable explanation of this specific error.
          type: string
        source:
          $ref: '#/components/schemas/ErrorSource'
          description: >-
            An object containing more specific information about the part of the
            request that caused the error.
        meta:
          type: object
          additionalProperties: true
      required:
        - type
    ErrorSource:
      title: ErrorSource
      description: >-
        The ErrorSource object provides additional context about the specific
        part of an API request that caused an error. It can point to either a
        field in the request document or a query parameter that contains invalid
        data.
      type: object
      properties:
        pointer:
          description: >-
            A JSON Pointer [RFC6901] to the associated entity in the request
            document.
          type: string
        parameter:
          description: A string indicating which URI query parameter caused the error.
          type: string
      required: []
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: Your Moonbase API key.

````