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

# Crear Pedidos

> Crear uno o múltiples pedidos

# Crear Pedidos

Crea uno o múltiples pedidos para fulfillment.

<Note>Requiere scope `write:orders`.</Note>

## Solicitud

```bash theme={null}
POST /api/v1/orders
```

### Parámetros del Body

Puedes enviar un pedido individual o un array de pedidos.

<ParamField body="order_tenant_id" type="string" required>
  Tu identificador único de pedido (usado para idempotencia)
</ParamField>

<ParamField body="assembly_date" type="string" required>
  Fecha en que el pedido debe ser preparado (YYYY-MM-DD)
</ParamField>

<ParamField body="customer_name" type="string">
  Nombre del cliente
</ParamField>

<ParamField body="shipping_address" type="string">
  Dirección de envío
</ParamField>

<ParamField body="order_detail" type="array" required>
  Array de líneas de pedido

  <Expandable title="propiedades del item">
    <ParamField body="barcode" type="string" required>
      Código de barras del producto
    </ParamField>

    <ParamField body="quantity" type="integer" required>
      Cantidad a preparar
    </ParamField>

    <ParamField body="price" type="number">
      Precio unitario
    </ParamField>
  </Expandable>
</ParamField>

## Respuesta

<ResponseField name="success" type="boolean">
  Si la solicitud fue exitosa
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="propiedades">
    <ResponseField name="created_count" type="integer">
      Número de pedidos creados
    </ResponseField>

    <ResponseField name="existing_count" type="integer">
      Número de pedidos que ya existían (omitidos)
    </ResponseField>

    <ResponseField name="orders" type="array">
      Array de objetos de pedidos creados
    </ResponseField>
  </Expandable>
</ResponseField>

## Ejemplos

### Pedido Individual

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.zenflow.com.ar/api/v1/orders" \
    -H "X-API-Key: zenflow_live_your_key" \
    -H "Content-Type: application/json" \
    -d '{
      "order_tenant_id": "ORD-001",
      "assembly_date": "2024-01-15",
      "customer_name": "Juan Pérez",
      "shipping_address": "Av. Corrientes 1234, CABA",
      "order_detail": [
        {
          "barcode": "7891234567890",
          "quantity": 2,
          "price": 29.99
        },
        {
          "barcode": "7891234567891",
          "quantity": 1,
          "price": 49.99
        }
      ]
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.zenflow.com.ar/api/v1/orders", {
    method: "POST",
    headers: {
      "X-API-Key": "zenflow_live_your_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      order_tenant_id: "ORD-001",
      assembly_date: "2024-01-15",
      customer_name: "Juan Pérez",
      order_detail: [
        { barcode: "7891234567890", quantity: 2 },
        { barcode: "7891234567891", quantity: 1 },
      ],
    }),
  });
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.zenflow.com.ar/api/v1/orders',
      headers={
          'X-API-Key': 'zenflow_live_your_key',
          'Content-Type': 'application/json'
      },
      json={
          'order_tenant_id': 'ORD-001',
          'assembly_date': '2024-01-15',
          'customer_name': 'Juan Pérez',
          'order_detail': [
              {'barcode': '7891234567890', 'quantity': 2},
              {'barcode': '7891234567891', 'quantity': 1}
          ]
      }
  )
  ```
</CodeGroup>

### Múltiples Pedidos

```bash theme={null}
curl -X POST "https://api.zenflow.com.ar/api/v1/orders" \
  -H "X-API-Key: zenflow_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "orders": [
      {
        "order_tenant_id": "ORD-001",
        "assembly_date": "2024-01-15",
        "order_detail": [{"barcode": "7891234567890", "quantity": 2}]
      },
      {
        "order_tenant_id": "ORD-002",
        "assembly_date": "2024-01-15",
        "order_detail": [{"barcode": "7891234567891", "quantity": 1}]
      }
    ]
  }'
```

### Respuesta Exitosa

```json theme={null}
{
  "success": true,
  "data": {
    "created_count": 2,
    "existing_count": 0,
    "orders": [
      {
        "id": 12345,
        "order_tenant_id": "ORD-001",
        "state_id": 1
      },
      {
        "id": 12346,
        "order_tenant_id": "ORD-002",
        "state_id": 1
      }
    ]
  }
}
```

## Respuestas de Error

### 400 Error de Validación

```json theme={null}
{
  "success": false,
  "error": {
    "code": "validation_error",
    "message": "Datos de pedido inválidos",
    "details": [
      {
        "index": 0,
        "error": "assembly_date es requerido"
      }
    ]
  }
}
```

### 400 Producto No Encontrado

```json theme={null}
{
  "success": false,
  "error": {
    "code": "creation_error",
    "message": "Producto con código de barras 7891234567890 no encontrado"
  }
}
```
