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

# Upload Files

> Uploads one or more files and attaches them to the selected order. Each file can be up to 10 MB.



## OpenAPI

````yaml https://logistics.api.smartcp.org/openapi/orders.openapi.json POST /orders/{order_id}/files
openapi: 3.0.3
info:
  title: SmartCP Logistics Orders API
  version: 1.0.0
  description: >-
    Order lookup and file attachment endpoints for the SmartCP Logistics public
    REST API.
servers:
  - url: https://logistics.api.smartcp.org/v1
    description: Production
security:
  - bearerAuth: []
    directoryHeader: []
paths:
  /orders/{order_id}/files:
    post:
      summary: Upload Files
      description: >-
        Uploads one or more files and attaches them to the selected order. Each
        file can be up to 10 MB.
      operationId: attachOrderFiles
      parameters:
        - name: order_id
          in: path
          required: true
          description: Order ID.
          schema:
            type: integer
          example: 4036230
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - files
              properties:
                category_id:
                  type: integer
                  nullable: true
                  description: Optional file category ID.
                files:
                  type: array
                  description: One or more files to upload. Maximum 10 MB per file.
                  items:
                    type: string
                    format: binary
            encoding:
              files:
                style: form
                explode: true
      responses:
        '201':
          description: At least one file uploaded successfully
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/BaseSuccessResponse'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/AttachFilesSuccessPayload'
              example:
                status: 201
                message: Created
                data:
                  message: Files attached successfully
                  order_id: 4036230
                  uploaded:
                    - id: 157
                      name: CMR.pdf
                      category_id: 1
                  failed: []
        '401':
          $ref: '#/components/responses/UnauthorizedResponse'
        '404':
          description: Order not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StringErrorResponse'
              example:
                status: 404
                message: Order not found
                data: null
        '422':
          description: Validation failed or no file could be attached
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/StringErrorResponse'
                  - type: object
                    required:
                      - status
                      - message
                      - data
                    properties:
                      status:
                        type: integer
                        example: 422
                      message:
                        type: string
                        example: No files were uploaded
                      data:
                        $ref: '#/components/schemas/AttachFilesFailurePayload'
              examples:
                validationError:
                  value:
                    status: 422
                    message: The files field is required.
                    data: null
                uploadFailed:
                  value:
                    status: 422
                    message: No files were uploaded
                    data:
                      message: No files were uploaded
                      order_id: 4036230
                      uploaded: []
                      failed:
                        - name: bad-file.pdf
                          error: Remote storage returned empty response
        '429':
          $ref: '#/components/responses/TooManyRequestsResponse'
components:
  schemas:
    BaseSuccessResponse:
      type: object
      required:
        - status
        - message
        - data
      properties:
        status:
          type: integer
          example: 200
        message:
          type: string
          example: OK
        data:
          nullable: true
    AttachFilesSuccessPayload:
      type: object
      required:
        - message
        - order_id
        - uploaded
        - failed
      properties:
        message:
          type: string
          example: Files attached successfully
        order_id:
          type: integer
          example: 4036230
        uploaded:
          type: array
          items:
            $ref: '#/components/schemas/UploadedOrderFile'
        failed:
          type: array
          items:
            $ref: '#/components/schemas/FailedUpload'
    StringErrorResponse:
      type: object
      required:
        - status
        - message
        - data
      properties:
        status:
          type: integer
          example: 401
        message:
          type: string
          example: Authentication failed
        data:
          nullable: true
          example: null
    AttachFilesFailurePayload:
      type: object
      required:
        - message
        - order_id
        - uploaded
        - failed
      properties:
        message:
          type: string
          example: No files were uploaded
        order_id:
          type: integer
          example: 4036230
        uploaded:
          type: array
          items:
            $ref: '#/components/schemas/UploadedOrderFile'
        failed:
          type: array
          items:
            $ref: '#/components/schemas/FailedUpload'
    UploadedOrderFile:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          example: 157
        name:
          type: string
          example: CMR.pdf
        category_id:
          type: integer
          nullable: true
          example: 1
    FailedUpload:
      type: object
      required:
        - name
        - error
      properties:
        name:
          type: string
          example: bad-file.pdf
        error:
          type: string
          example: Remote storage returned empty response
  responses:
    UnauthorizedResponse:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StringErrorResponse'
          example:
            status: 401
            message: Authentication failed
            data: null
    TooManyRequestsResponse:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StringErrorResponse'
          example:
            status: 429
            message: Too Many Attempts.
            data: null
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: Client API key sent as a bearer token.
    directoryHeader:
      type: apiKey
      in: header
      name: X-Client-Directory
      description: >-
        Client directory identifier. Legacy `directory` header is still accepted
        for backward compatibility.

````