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

# Crear un pedido

> Creates a confirmed order. Send an Idempotency-Key header to make retries safe: repeating the request with the same key returns the originally created order (200) instead of creating a duplicate.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/orders
openapi: 3.1.0
info:
  title: Caudal Public API
  version: 1.0.0
  description: >-
    REST API for HORECA distributors to integrate their ERP with Caudal.
    Authenticate with an API key issued from the Caudal dashboard
    (WorkOS-backed). Pass it as 'Authorization: Bearer <key>'. Base URL:
    https://api.caudalflow.com
servers:
  - url: https://api.caudalflow.com
security:
  - bearerAuth: []
tags:
  - name: Pedidos
    description: Leer y crear pedidos.
  - name: Cuentas
    description: Leer y crear las cuentas de los clientes.
  - name: Productos
    description: Leer el catálogo.
paths:
  /v1/orders:
    post:
      tags:
        - Pedidos
      summary: Crear un pedido
      description: >-
        Creates a confirmed order. Send an Idempotency-Key header to make
        retries safe: repeating the request with the same key returns the
        originally created order (200) instead of creating a duplicate.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrderRequest'
      responses:
        '200':
          description: >-
            Replay of a previous request with the same Idempotency-Key. The
            original resource comes back and nothing is created.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Order'
        '201':
          description: The created resource.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Order'
        '400':
          $ref: '#/components/responses/Error'
          description: The request is malformed (code invalid_request).
        '401':
          $ref: '#/components/responses/Error'
          description: The API key is missing, invalid or not linked to an organization.
        '403':
          $ref: '#/components/responses/Error'
          description: The API key lacks the scope this route requires.
        '409':
          $ref: '#/components/responses/Error'
          description: >-
            The Idempotency-Key already identifies a resource of a different
            type (code idempotency_key_conflict). Send a new key.
        '422':
          $ref: '#/components/responses/Error'
          description: >-
            A line matches no catalog product, or still holds several matches.
            Resolve the line and retry. (code order_items_unresolved)
        '429':
          $ref: '#/components/responses/Error'
          description: >-
            The organization exceeded its rate limit. Retry after the delay in
            Retry-After.
      security:
        - bearerAuth:
            - orders:write
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 1
        maxLength: 255
      description: >-
        Client-generated unique key (e.g. a UUID), scoped to the organization.
        Retrying a request with the same key returns the original resource with
        status 200 instead of creating a duplicate. One key space serves every
        POST route: a key already used on another route answers 409.
  schemas:
    CreateOrderRequest:
      type: object
      properties:
        account_id:
          type: string
          minLength: 1
        notes:
          anyOf:
            - type: string
            - type: 'null'
        items:
          minItems: 1
          type: array
          items:
            type: object
            properties:
              product_id:
                anyOf:
                  - type: string
                    minLength: 1
                  - type: 'null'
              sku:
                anyOf:
                  - type: string
                  - type: 'null'
              product_name:
                type: string
                minLength: 1
                description: >-
                  A human-readable label. Never the join key — use product_id or
                  sku.
              quantity:
                type: number
                exclusiveMinimum: 0
                maximum: 1000000
              unit:
                anyOf:
                  - type: string
                  - type: 'null'
              notes:
                anyOf:
                  - type: string
                  - type: 'null'
              unit_price:
                anyOf:
                  - type: number
                    minimum: 0
                  - type: 'null'
            required:
              - product_name
              - quantity
      required:
        - account_id
        - items
    Order:
      type: object
      properties:
        id:
          type: string
        status:
          type: string
          enum:
            - pending
            - reviewed
            - confirmed
            - delivered
            - cancelled
        channel:
          type: string
          enum:
            - voice
            - whatsapp
            - api
            - manual
        account:
          anyOf:
            - type: object
              properties:
                id:
                  type: string
                name:
                  type: string
              required:
                - id
                - name
            - type: 'null'
        items:
          type: array
          items:
            $ref: '#/components/schemas/OrderItem'
        notes:
          anyOf:
            - type: string
            - type: 'null'
        delivery_address:
          anyOf:
            - $ref: '#/components/schemas/DeliveryAddress'
            - type: 'null'
        captured_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
        reviewed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
        confirmed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
      required:
        - id
        - status
        - channel
        - account
        - items
        - notes
        - delivery_address
        - captured_at
        - reviewed_at
        - confirmed_at
    OrderItem:
      type: object
      properties:
        product_id:
          anyOf:
            - type: string
            - type: 'null'
        product_name:
          type: string
        quantity:
          type: number
        unit:
          anyOf:
            - type: string
            - type: 'null'
        notes:
          anyOf:
            - type: string
            - type: 'null'
        unit_raw:
          anyOf:
            - type: string
            - type: 'null'
        product_unit:
          anyOf:
            - type: string
            - type: 'null'
        base_unit_qty_micro_at_capture:
          anyOf:
            - type: number
            - type: 'null'
        notes_source:
          anyOf:
            - type: string
              enum:
                - customer
                - previous_order
                - reviewer
            - type: 'null'
        sku:
          anyOf:
            - type: string
            - type: 'null'
        unit_price:
          anyOf:
            - type: number
            - type: 'null'
        price_source:
          anyOf:
            - type: string
              enum:
                - explicit
                - account
                - catalog
            - type: 'null'
        resolution:
          anyOf:
            - type: string
              enum:
                - product
                - discarded
            - type: 'null'
        discard_reason:
          anyOf:
            - type: string
            - type: 'null'
      required:
        - product_id
        - product_name
        - quantity
        - unit
        - notes
        - unit_raw
        - product_unit
        - base_unit_qty_micro_at_capture
        - notes_source
        - sku
        - unit_price
        - price_source
        - resolution
        - discard_reason
    DeliveryAddress:
      type: object
      properties:
        label:
          anyOf:
            - type: string
            - type: 'null'
        address:
          type: string
      required:
        - label
        - address
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - missing_api_key
                - invalid_api_key
                - insufficient_scope
                - rate_limited
                - not_found
                - invalid_request
                - idempotency_key_conflict
                - internal_error
                - erased_customer
                - order_items_unresolved
            message:
              type: string
          required:
            - code
            - message
      required:
        - error
  responses:
    Error:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key issued from the Caudal dashboard. Scopes are enforced per route:
        orders:read, orders:write, accounts:read, accounts:write, products:read.

````