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

# Actualizar compra

> Actualiza una compra existente y devuelve el detalle persistido. El campo items es requerido y reemplaza los renglones de la compra. Requiere Idempotency-Key.



## OpenAPI

````yaml /api-reference/openapi.json put /api/v1/purchases/{purchase_id}
openapi: 3.1.0
info:
  title: La Pyme API
  description: >-
    Resources and workflows for purchases, sales, inventory, contacts, products,
    reports, and settings.
  version: 1.0.0
  contact:
    name: La Pyme Support
    email: hola@lapyme.com.ar
  license:
    name: Proprietary
    url: https://lapyme.com.ar/terminos
servers:
  - url: https://api.lapyme.com.ar
    description: Servidor de producción
security:
  - bearerAuth: []
tags:
  - name: API
    description: Public API operations for La Pyme integrations.
paths:
  /api/v1/purchases/{purchase_id}:
    put:
      tags:
        - API
      summary: Actualizar compra
      description: >-
        Actualiza una compra existente y devuelve el detalle persistido. El
        campo items es requerido y reemplaza los renglones de la compra.
        Requiere Idempotency-Key.
      operationId: updateApiPurchase
      parameters:
        - name: purchase_id
          in: path
          description: ID de la compra
          required: true
          schema:
            type: string
            format: uuid
        - name: Idempotency-Key
          in: header
          description: Clave estable para deduplicar reintentos de la misma operación.
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiPurchaseUpdateRequest'
      responses:
        '200':
          description: Compra actualizada exitosamente
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiPurchaseDetailResponse'
        '400':
          description: Solicitud inválida
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: Solicitud inválida
                      retryable: false
                      details: []
        '401':
          description: API key faltante o inválida
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: API key faltante o inválida
                      retryable: false
                      details: []
        '403':
          description: Scopes insuficientes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: Scopes insuficientes
                      retryable: false
                      details: []
        '404':
          description: Compra no encontrada
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: Compra no encontrada
                      retryable: false
                      details: []
        '412':
          description: Precondición de negocio no satisfecha
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: Precondición de negocio no satisfecha
                      retryable: false
                      details: []
        '429':
          description: Límite de solicitudes excedido para la organización
          headers:
            Retry-After:
              description: Segundos a esperar antes de volver a intentar la solicitud.
              schema:
                type: string
                example: '30'
            X-RateLimit-Limit:
              description: Límite de la ventana activa.
              schema:
                type: string
                example: '5000'
            X-RateLimit-Remaining:
              description: Solicitudes restantes en la ventana activa.
              schema:
                type: string
                example: '0'
            X-RateLimit-Reset:
              description: Segundos restantes hasta el reset de la ventana activa.
              schema:
                type: string
                example: '30'
            RateLimit-Limit:
              description: Límite de la ventana activa en formato estándar.
              schema:
                type: string
                example: '5000'
            RateLimit-Remaining:
              description: Solicitudes restantes en la ventana activa en formato estándar.
              schema:
                type: string
                example: '0'
            RateLimit-Reset:
              description: >-
                Segundos hasta el reset de la ventana activa en formato
                estándar.
              schema:
                type: string
                example: '30'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: RATE_LIMITED
                  value:
                    request_id: req_rate_limit_1
                    error:
                      type: rate_limit_error
                      code: RATE_LIMITED
                      message: >-
                        The organization request limit was reached. Try again
                        later.
                      retryable: true
                      details: []
        '500':
          description: Error interno del servidor
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
              examples:
                default:
                  summary: INVALID_REQUEST
                  value:
                    request_id: req_error_1
                    error:
                      type: invalid_request_error
                      code: INVALID_REQUEST
                      message: Error interno del servidor
                      retryable: false
                      details: []
components:
  schemas:
    ApiPurchaseUpdateRequest:
      type: object
      properties:
        supplier_id:
          type: string
          format: uuid
        voucher_type:
          type: integer
          minimum: 1
        import_document_role:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnum9e7af09974'
            - type: 'null'
          description: Rol del comprobante dentro del flujo de importacion.
        import_source_purchase_id:
          description: ID de la factura comercial asociada al despacho aduanero.
          type: string
          format: uuid
        import_nationalization_status:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnumf0d69c3d87'
            - type: 'null'
          description: Estado de nacionalizacion de la factura comercial de importacion.
        customs_dispatch_number:
          description: >-
            Numero de despacho aduanero informado por el proveedor. Hasta 32
            caracteres.
          type: string
        supplier_invoice_number:
          description: Numero de comprobante del proveedor. Hasta 120 caracteres.
          type: string
        invoice_date:
          description: Fecha del comprobante en formato YYYY-MM-DD.
          type: string
          format: date
        account_date:
          description: Fecha contable de la compra en formato YYYY-MM-DD.
          type: string
          format: date
        due_date:
          description: Fecha de vencimiento en formato YYYY-MM-DD.
          type: string
          format: date
        payment_term_id:
          anyOf:
            - anyOf:
                - $ref: '#/components/schemas/ApiSharedEnumd34af90520'
                - type: 'null'
            - type: 'null'
        payment_term_days:
          anyOf:
            - type: integer
              minimum: 0
              maximum: 365
              description: >-
                Cantidad de días hasta el vencimiento. Usá 0 para Contado. Se
                prefiere sobre paymentTermId.
            - type: 'null'
        vat_perception_amount:
          type: integer
          minimum: 0
        national_tax_amount:
          type: integer
          minimum: 0
        gross_income_tax_amount:
          type: integer
          minimum: 0
        gross_income_tax_breakdown:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObject95929ea589'
        municipal_tax_amount:
          type: integer
          minimum: 0
        internal_tax_amount:
          type: integer
          minimum: 0
        other_tax_amount:
          type: integer
          minimum: 0
        warehouse_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
        products_received:
          type: boolean
        update_product_variant_cost:
          type: boolean
        items:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObject65e544dba2'
        subtotal:
          type: integer
          minimum: 0
        tax_amount:
          type: integer
          minimum: 0
        total:
          type: integer
          minimum: 0
        discount:
          type: integer
          minimum: 0
        exempt_amount:
          type: integer
          minimum: 0
        non_taxed_amount:
          type: integer
          minimum: 0
        base_amount:
          type: integer
          minimum: 0
        vat_breakdown:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObjectfb7405a472'
        manual_account_allocations:
          $ref: '#/components/schemas/ApiSharedObjectbea003a73d'
        notes:
          type: string
        currency:
          $ref: '#/components/schemas/ApiSharedEnum6cfb146157'
        exchange_rate:
          type: number
          exclusiveMinimum: 0
        pdf_path:
          type: string
        vat_category:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnum822a963f55'
            - type: 'null'
      required:
        - voucher_type
        - items
        - currency
      additionalProperties: false
    ApiPurchaseDetailResponse:
      type: object
      required:
        - request_id
        - data
      properties:
        request_id:
          type: string
        data:
          $ref: '#/components/schemas/ApiPurchaseDetail'
    ApiErrorEnvelope:
      type: object
      properties:
        request_id:
          type: string
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - api_error
                - authentication_error
                - authorization_error
                - business_error
                - external_dependency_error
                - idempotency_error
                - invalid_request_error
                - rate_limit_error
            code:
              type: string
            message:
              type: string
            retryable:
              type: boolean
            details:
              type: array
              items:
                $ref: '#/components/schemas/ApiSharedObjectc671832641'
          required:
            - type
            - code
            - message
            - retryable
            - details
          additionalProperties: false
      required:
        - request_id
        - error
      additionalProperties: false
    ApiSharedEnum9e7af09974:
      type: string
      enum:
        - commercial_invoice
        - customs_dispatch
        - customs_dispatch_reversal
    ApiSharedEnumf0d69c3d87:
      type: string
      enum:
        - pending_nationalization
        - partially_nationalized
        - fully_nationalized
    ApiSharedEnumd34af90520:
      type: string
      enum:
        - days_7
        - days_15
        - days_30
        - days_45
        - days_60
        - days_90
        - days_30_60
        - days_30_60_90
    ApiSharedObject95929ea589:
      type: object
      properties:
        province_id:
          type: integer
        amount:
          type: integer
          minimum: 0
      required:
        - province_id
        - amount
      additionalProperties: false
    ApiSharedObject65e544dba2:
      type: object
      properties:
        product_id:
          type: string
          format: uuid
        name:
          type: string
        quantity:
          type: number
          exclusiveMinimum: 0
        unit_cost:
          type: integer
          minimum: 0
        subtotal:
          type: integer
          minimum: 0
        total:
          type: integer
          minimum: 0
        tax_rate_id:
          type: integer
          minimum: 0
        is_exempt:
          type: boolean
        discount_percentage:
          type: number
          minimum: 0
          maximum: 100
        purchase_order_item_id:
          type: string
          format: uuid
        vat_category:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnum822a963f55'
            - type: 'null'
        account_id:
          description: ID de cuenta contable imputable de Activo o Gasto para este renglon.
          type: string
          format: uuid
        cost_center1_id:
          type: string
          format: uuid
        cost_center2_id:
          type: string
          format: uuid
        cost_center3_id:
          type: string
          format: uuid
      required:
        - quantity
        - unit_cost
      additionalProperties: false
    ApiSharedObjectfb7405a472:
      type: object
      properties:
        tax_rate_id:
          type: integer
          minimum: 0
        base_amount:
          type: integer
          minimum: 0
        tax_amount:
          type: integer
          minimum: 0
      required:
        - tax_rate_id
        - base_amount
        - tax_amount
      additionalProperties: false
    ApiSharedObjectbea003a73d:
      type: object
      properties:
        gravado21:
          type: string
          format: uuid
        gravado27:
          type: string
          format: uuid
        gravado105:
          type: string
          format: uuid
        gravado25:
          type: string
          format: uuid
        gravado5:
          type: string
          format: uuid
        non_taxed_amount:
          type: string
          format: uuid
        exento:
          type: string
          format: uuid
        base_amount:
          type: string
          format: uuid
      additionalProperties: false
    ApiSharedEnum6cfb146157:
      type: string
      enum:
        - PES
        - DOL
    ApiSharedEnum822a963f55:
      type: string
      enum:
        - goods
        - fixed_assets
        - leases
        - services
    ApiPurchaseDetail:
      type: object
      properties:
        object:
          type: string
          const: purchase
        id:
          type: string
          format: uuid
        accounting:
          $ref: '#/components/schemas/ApiSharedObject799d3e3f37'
        voucher_type:
          type: string
        import_document_role:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnum9e7af09974'
            - type: 'null'
          description: Rol del comprobante dentro del flujo de importacion.
        import_source_purchase_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          description: ID de la factura comercial asociada al despacho aduanero.
        import_nationalization_status:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnumf0d69c3d87'
            - type: 'null'
          description: Estado de nacionalizacion de la factura comercial de importacion.
        customs_dispatch_number:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Numero de despacho aduanero informado por el proveedor. Hasta 32
            caracteres.
        supplier_invoice_number:
          anyOf:
            - type: string
            - type: 'null'
          description: Numero de comprobante del proveedor. Hasta 120 caracteres.
        invoice_date:
          anyOf:
            - type: string
            - type: 'null'
          description: Fecha del comprobante en formato YYYY-MM-DD.
        account_date:
          anyOf:
            - type: string
            - type: 'null'
          description: Fecha contable de la compra en formato YYYY-MM-DD.
        due_date:
          anyOf:
            - type: string
            - type: 'null'
          description: Fecha de vencimiento en formato YYYY-MM-DD.
        payment_term_id:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnumd34af90520'
            - type: 'null'
        payment_term_days:
          anyOf:
            - type: integer
              minimum: 0
              maximum: 365
              description: >-
                Cantidad de días hasta el vencimiento. Usá 0 para Contado. Se
                prefiere sobre paymentTermId.
            - type: 'null'
        vat_perception_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        national_tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        gross_income_tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        gross_income_tax_breakdown:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObject95929ea589'
        municipal_tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        internal_tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        other_tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        subtotal:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        tax_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        exempt_amount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        total:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        balance:
          anyOf:
            - type: integer
            - type: 'null'
        discount:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
        vat_breakdown:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObjectfb7405a472'
        notes:
          anyOf:
            - type: string
            - type: 'null'
        vat_category:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedEnum822a963f55'
            - type: 'null'
        currency:
          type: string
        exchange_rate:
          type: string
        pdf_path:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Deprecated internal storage key retained for V1 compatibility. Use
            document.url instead; it is stable, authenticated, and
            storage-provider-neutral.
          deprecated: true
        document:
          $ref: '#/components/schemas/ApiSharedObject890679c3fd'
        created_at:
          type: string
          format: date-time
        supplier:
          anyOf:
            - type: object
              properties:
                id:
                  anyOf:
                    - type: string
                      format: uuid
                    - type: 'null'
                name:
                  anyOf:
                    - type: string
                    - type: 'null'
                email:
                  anyOf:
                    - type: string
                    - type: 'null'
                phone:
                  anyOf:
                    - type: string
                    - type: 'null'
                tax_id:
                  anyOf:
                    - type: string
                    - type: 'null'
                tax_id_type:
                  anyOf:
                    - type: string
                    - type: 'null'
                tax_category:
                  anyOf:
                    - type: string
                    - type: 'null'
                address:
                  anyOf:
                    - type: string
                    - type: 'null'
                city:
                  anyOf:
                    - type: string
                    - type: 'null'
                province_id:
                  anyOf:
                    - type: string
                    - type: 'null'
                postal_code:
                  anyOf:
                    - type: string
                    - type: 'null'
                payment_term_id:
                  anyOf:
                    - type: string
                    - type: 'null'
                payment_term_days:
                  anyOf:
                    - type: integer
                      minimum: 0
                      maximum: 365
                      description: >-
                        Cantidad de días hasta el vencimiento. Usá 0 para
                        Contado. Se prefiere sobre paymentTermId.
                    - type: 'null'
              required:
                - id
                - name
                - email
                - phone
                - tax_id
                - tax_id_type
                - tax_category
                - address
                - city
                - province_id
                - postal_code
                - payment_term_id
                - payment_term_days
              additionalProperties: false
            - type: 'null'
        warehouse:
          anyOf:
            - $ref: '#/components/schemas/ApiSharedObject8aeeceaf0f'
            - type: 'null'
        items:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              name:
                anyOf:
                  - type: string
                  - type: 'null'
              quantity:
                type: number
                exclusiveMinimum: 0
              unit_cost:
                anyOf:
                  - type: integer
                    minimum: 0
                  - type: 'null'
              subtotal:
                anyOf:
                  - type: integer
                    minimum: 0
                  - type: 'null'
              tax_rate_id:
                anyOf:
                  - type: integer
                    minimum: 0
                  - type: 'null'
              is_exempt:
                anyOf:
                  - type: boolean
                  - type: 'null'
              total:
                anyOf:
                  - type: integer
                    minimum: 0
                  - type: 'null'
              discount_percentage:
                anyOf:
                  - type: number
                  - type: 'null'
              purchase_order_item_id:
                anyOf:
                  - type: string
                    format: uuid
                  - type: 'null'
              vat_category:
                anyOf:
                  - $ref: '#/components/schemas/ApiSharedEnum822a963f55'
                  - type: 'null'
              product:
                anyOf:
                  - type: object
                    properties:
                      id:
                        type: string
                        format: uuid
                      sku:
                        anyOf:
                          - type: string
                          - type: 'null'
                      name:
                        anyOf:
                          - type: string
                          - type: 'null'
                      product_type:
                        anyOf:
                          - $ref: '#/components/schemas/ApiSharedEnumff49232140'
                          - type: 'null'
                    required:
                      - id
                      - sku
                      - name
                      - product_type
                    additionalProperties: false
                  - type: 'null'
              purchase_order:
                anyOf:
                  - type: object
                    properties:
                      id:
                        type: string
                        format: uuid
                      formatted_order_number:
                        anyOf:
                          - type: string
                          - type: 'null'
                    required:
                      - id
                      - formatted_order_number
                    additionalProperties: false
                  - type: 'null'
            required:
              - id
              - name
              - quantity
              - unit_cost
              - subtotal
              - tax_rate_id
              - is_exempt
              - total
              - discount_percentage
              - purchase_order_item_id
              - vat_category
              - product
              - purchase_order
            additionalProperties: false
      required:
        - object
        - id
        - voucher_type
        - import_document_role
        - import_source_purchase_id
        - import_nationalization_status
        - customs_dispatch_number
        - supplier_invoice_number
        - invoice_date
        - account_date
        - due_date
        - payment_term_id
        - payment_term_days
        - vat_perception_amount
        - national_tax_amount
        - gross_income_tax_amount
        - gross_income_tax_breakdown
        - municipal_tax_amount
        - internal_tax_amount
        - other_tax_amount
        - subtotal
        - tax_amount
        - exempt_amount
        - total
        - balance
        - discount
        - vat_breakdown
        - notes
        - vat_category
        - currency
        - exchange_rate
        - pdf_path
        - document
        - created_at
        - supplier
        - warehouse
        - items
      additionalProperties: false
    ApiSharedObjectc671832641:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        field:
          type: string
      required:
        - code
        - message
      additionalProperties: false
    ApiSharedObject799d3e3f37:
      type: object
      properties:
        object:
          type: string
          const: accounting_evidence
        status:
          $ref: '#/components/schemas/ApiSharedEnum8b51d9e8f5'
        journal_entry_ids:
          type: array
          items:
            type: string
            format: uuid
        journal_entries_url:
          anyOf:
            - type: string
            - type: 'null'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiSharedObject76de9df039'
      required:
        - object
        - status
        - journal_entry_ids
        - journal_entries_url
        - warnings
      additionalProperties: false
    ApiSharedObject890679c3fd:
      type: object
      properties:
        status:
          $ref: '#/components/schemas/ApiSharedEnum1ba2b57809'
        url:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Stable authenticated La Pyme API path. Present only when status is
            ready; follow redirects when downloading.
      required:
        - status
        - url
      additionalProperties: false
      description: >-
        Document availability. The URL requires bearer authentication and never
        contains a storage path or signed query string.
    ApiSharedObject8aeeceaf0f:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
      required:
        - id
        - name
      additionalProperties: false
    ApiSharedEnumff49232140:
      type: string
      enum:
        - product
        - service
        - combo
        - kit
    ApiSharedEnum8b51d9e8f5:
      type: string
      enum:
        - not_enabled
        - not_applicable
        - pending
        - posted
        - failed
    ApiSharedObject76de9df039:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
      required:
        - code
        - message
      additionalProperties: false
    ApiSharedEnum1ba2b57809:
      type: string
      enum:
        - ready
        - pending
        - failed
        - missing
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Incluí tu API key en el header Authorization con el prefijo Bearer.

````