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

# Importar paquetes en lote

> Crea paquetes en estado "En bodega". Por cada ítem debe enviarse `id_sucursal` o `sucursal`.
Si ya existe un paquete con el mismo `wr` en la empresa, el ítem se omite (skipped).
Máximo 500 ítems por solicitud.




## OpenAPI

````yaml /openapi.yaml post /packages/import
openapi: 3.0.0
info:
  title: SmartPYME External API
  description: >
    API Externa de SmartPYME para proveedores terceros.


    Permite consultar y registrar ventas, consultar inventario y devoluciones, e
    importar paquetes usando autenticación por API Key.


    ## Autenticación

    Todas las requests requieren un API Key válido en el header Authorization:

    ```

    Authorization: Bearer {tu_api_key}

    ```


    ## Rate Limiting

    - Sin filtros de fecha: 1000 requests/hora

    - Con filtros de fecha: 2000 requests/hora


    ## Paginación

    Todos los endpoints de lista soportan paginación:

    - `page`: Número de página (default: 1)

    - `per_page`: Registros por página (1-200, default: 100)
  version: 1.4.0
  contact:
    name: SmartPYME Support
    email: soporte@smartpyme.com
  license:
    name: Propietario
    url: https://smartpyme.com/terms
servers:
  - url: https://tu-dominio.com/api/external/v1
    description: Servidor de Producción
  - url: http://localhost/api/external/v1
    description: Servidor de Desarrollo
security:
  - ApiKeyAuth: []
paths:
  /packages/import:
    post:
      tags:
        - Paquetes
      summary: Importar paquetes en lote
      description: >
        Crea paquetes en estado "En bodega". Por cada ítem debe enviarse
        `id_sucursal` o `sucursal`.

        Si ya existe un paquete con el mismo `wr` en la empresa, el ítem se
        omite (skipped).

        Máximo 500 ítems por solicitud.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PackagesImportRequest'
      responses:
        '200':
          description: Procesamiento completado
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PackagesImportResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          description: La empresa no tiene usuario activo para registrar paquetes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
components:
  schemas:
    PackagesImportRequest:
      type: object
      required:
        - packages
      properties:
        packages:
          type: array
          minItems: 1
          maxItems: 500
          items:
            $ref: '#/components/schemas/PackageImportItem'
    PackagesImportResponse:
      type: object
      properties:
        success:
          type: boolean
        created:
          type: integer
        skipped:
          type: integer
        errors:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              wr:
                type: string
                nullable: true
              message:
                type: string
        items:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              wr:
                type: string
                nullable: true
              status:
                type: string
                enum:
                  - created
                  - skipped
              id:
                type: integer
                nullable: true
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
          description: Mensaje de error
        code:
          type: integer
          description: Código de error HTTP
      required:
        - success
        - error
        - code
    PackageImportItem:
      type: object
      required:
        - cliente
        - codigo_asesor
        - wr
        - guia
        - piezas
        - embalaje
        - peso
        - precio
        - cuenta_a_terceros
        - otros
        - total
      properties:
        id_sucursal:
          type: integer
          description: Prioridad sobre sucursal
        sucursal:
          type: string
          description: Obligatorio si no se envía id_sucursal
        cliente:
          type: string
        codigo_asesor:
          type: string
        wr:
          type: string
        guia:
          type: string
        piezas:
          type: number
        embalaje:
          type: string
        peso:
          type: number
        precio:
          type: number
        cuenta_a_terceros:
          type: number
        otros:
          type: number
        total:
          type: number
        transportista:
          type: string
          nullable: true
        consignatario:
          type: string
          nullable: true
        transportador:
          type: string
          nullable: true
        seguimiento:
          type: string
          nullable: true
        volumen:
          type: number
          nullable: true
        nota:
          type: string
          nullable: true
    ValidationErrorResponse:
      allOf:
        - $ref: '#/components/schemas/ErrorResponse'
        - type: object
          properties:
            details:
              type: object
              description: Detalles de errores de validación
              example:
                fecha_inicio:
                  - El campo fecha inicio debe ser una fecha válida.
                per_page:
                  - El campo per page no puede ser mayor que 200.
  responses:
    BadRequest:
      description: Parámetros inválidos
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationErrorResponse'
    Unauthorized:
      description: API Key inválido o faltante
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            success: false
            error: API key inválido o empresa inactiva
            code: 401
    RateLimitExceeded:
      description: Rate limit excedido
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            success: false
            error: >-
              Rate limit excedido. Máximo 1000 requests por hora (2000 con
              filtros de fecha).
            code: 429
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      description: |
        API Key de la empresa en formato Bearer token.

        Ejemplo: `Authorization: Bearer G8RCjH11DabBNjnX7wO5`

````