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

# Crear o actualizar documento

> Sincroniza un documento externo, su cliente y líneas. `totalMinor`, cuando se envía, debe corresponder con las líneas.



## OpenAPI

````yaml /openapi/integrations-v1.json post /integrations/v1/{companyId}/collection-documents/upsert
openapi: 3.1.0
info:
  title: Cobrix API de integraciones
  version: 1.0.0
  description: >-
    API firmada para sincronizar clientes, documentos de cobro, links y pagos
    verificados. Los campos monetarios terminados en Minor usan unidades
    menores.
  license:
    name: Propietaria
    url: https://cobrix.co/terms
servers:
  - url: https://api.cobrix.co/api
    description: Producción
  - url: https://sandbox-api.cobrix.co/api
    description: Sandbox
security:
  - bearerAuth: []
tags:
  - name: Clientes
    description: Identidades externas vinculadas al source de la llave.
  - name: Documentos de cobro
    description: Documentos o cargos importados desde un sistema externo.
  - name: Links de cobro
    description: Sesiones de checkout para documentos abiertos.
  - name: Pagos
    description: Pagos verificados y su aplicación financiera.
paths:
  /integrations/v1/{companyId}/collection-documents/upsert:
    post:
      tags:
        - Documentos de cobro
      summary: Crear o actualizar documento
      description: >-
        Sincroniza un documento externo, su cliente y líneas. `totalMinor`,
        cuando se envía, debe corresponder con las líneas.
      operationId: upsertCollectionDocument
      parameters:
        - $ref: '#/components/parameters/CompanyId'
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/CobrixTimestamp'
        - $ref: '#/components/parameters/CobrixSignature'
        - $ref: '#/components/parameters/RequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertCollectionDocumentRequest'
      responses:
        '201':
          description: Documento procesado
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertCollectionDocumentResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    CompanyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Empresa vinculada a la llave.
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema:
        type: string
        minLength: 1
      description: Identificador estable de la operación.
    CobrixTimestamp:
      name: Cobrix-Timestamp
      in: header
      required: true
      schema:
        type: string
        pattern: ^[0-9]{10}$
      description: Segundos Unix dentro de una ventana de cinco minutos.
    CobrixSignature:
      name: Cobrix-Signature
      in: header
      required: true
      schema:
        type: string
        pattern: ^v1=[a-f0-9]{64}$
      description: HMAC-SHA256 de timestamp, método, ruta y cuerpo crudo.
    RequestId:
      name: X-Request-Id
      in: header
      required: false
      schema:
        type: string
      description: Identificador opcional para correlación de soporte.
  schemas:
    UpsertCollectionDocumentRequest:
      type: object
      required:
        - source
        - externalDocumentId
        - customerExternalId
        - customer
        - issueDate
        - dueDate
        - currency
        - lines
      properties:
        source:
          type: string
          minLength: 1
        externalDocumentId:
          type: string
          minLength: 1
        customerExternalId:
          type: string
          minLength: 1
        customer:
          $ref: '#/components/schemas/ExternalCustomerCore'
        issueDate:
          type: string
          format: date-time
        dueDate:
          type: string
          format: date-time
        cutDate:
          type: string
          format: date-time
        currency:
          type: string
          enum:
            - USD
            - VES
            - usd
            - ves
        totalMinor:
          type: number
          minimum: 0
        lines:
          type: array
          items:
            $ref: '#/components/schemas/CollectionDocumentLineRequest'
        metadata:
          type: object
          additionalProperties: true
        status:
          type: string
      example:
        source: erp_acme
        externalDocumentId: invoice-1001
        customerExternalId: customer-1001
        customer:
          type: individual
          name: Cliente de prueba
          email: cliente@example.com
        issueDate: '2026-07-14T00:00:00Z'
        dueDate: '2026-08-14T00:00:00Z'
        currency: USD
        totalMinor: 2025
        lines:
          - description: Plan mensual
            quantity: 1
            unitAmountMinor: 2025
    UpsertCollectionDocumentResponse:
      type: object
      required:
        - invoiceId
        - companyCustomerId
        - customerExternalId
        - source
        - externalDocumentId
        - status
        - invoiceStatus
        - currency
        - totalMinor
        - balanceMinor
        - customer
      properties:
        invoiceId:
          type: string
          format: uuid
        invoiceNumber:
          type: string
        companyCustomerId:
          type: string
          format: uuid
        customerExternalId:
          type: string
        source:
          type: string
        externalDocumentId:
          type: string
        status:
          type: string
          enum:
            - created
            - updated
            - unchanged
            - rejected
        invoiceStatus:
          type: string
        currency:
          type: string
        totalMinor:
          type: integer
        balanceMinor:
          type: integer
        customer:
          $ref: '#/components/schemas/UpsertCustomerResponse'
    ExternalCustomerCore:
      type: object
      required:
        - type
        - name
      properties:
        type:
          type: string
          enum:
            - individual
            - business
        name:
          type: string
          minLength: 1
          maxLength: 200
        email:
          type:
            - string
            - 'null'
          format: email
        phone:
          type:
            - string
            - 'null'
        taxId:
          type:
            - string
            - 'null'
        customerCode:
          type:
            - string
            - 'null'
        metadata:
          type: object
          additionalProperties: true
    CollectionDocumentLineRequest:
      type: object
      required:
        - description
        - quantity
        - unitAmountMinor
      properties:
        description:
          type: string
          minLength: 1
        quantity:
          type: number
          minimum: 1
        unitAmountMinor:
          type: number
          minimum: 0
        periodStart:
          type: string
          format: date-time
        periodEnd:
          type: string
          format: date-time
        metadata:
          type: object
          additionalProperties: true
    UpsertCustomerResponse:
      type: object
      required:
        - customerId
        - companyCustomerId
        - source
        - externalCustomerId
        - status
      properties:
        customerId:
          type: string
          format: uuid
        companyCustomerId:
          type: string
          format: uuid
        source:
          type: string
        externalCustomerId:
          type: string
        status:
          type: string
          enum:
            - created
            - updated
            - unchanged
            - rejected
    IntegrationError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            requestId:
              type:
                - string
                - 'null'
  responses:
    BadRequest:
      description: Payload, firma o idempotencia faltante
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IntegrationError'
    Unauthorized:
      description: Llave o firma inválida
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IntegrationError'
          example:
            error:
              code: invalid_api_key
              message: The API key is missing or invalid.
              requestId: req-1001
    Forbidden:
      description: Empresa o scope no autorizado
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IntegrationError'
    Conflict:
      description: Conflicto de idempotencia o estado financiero
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IntegrationError'
    RateLimited:
      description: Límite por llave y ruta excedido
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/IntegrationError'
          example:
            error:
              code: rate_limited
              message: Too many requests for this API key.
              requestId: req-1001
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Cobrix API key
      description: Llave cbx_live creada para el partner.

````