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

# Agregar compras

> Suma pedidos, ingresos, ticket promedio y clientes únicos con los mismos filtros del listado, con ranking opcional por dimensión, incluido UTM.



## OpenAPI

````yaml /openapi.es.json get /v1/purchases/stats
openapi: 3.1.0
info:
  title: API de Bevits
  version: 1.0.0
  description: >-
    API pública de solo lectura para consultar datos de CRM, compras y
    automatización de una organización de Bevits.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.bevits.com
    description: Producción
security:
  - bearerAuth: []
tags:
  - name: Sistema
    description: Disponibilidad de la API.
  - name: Identidad
    description: Identidad de la organización y de la clave API.
  - name: Clientes
    description: Clientes y sus relaciones.
  - name: Segmentos
    description: Segmentos de clientes.
  - name: Compras
    description: Compras importadas desde las integraciones.
  - name: Datos del CRM
    description: Etiquetas y definiciones de atributos.
  - name: Automatizaciones
    description: Flows de automatización.
  - name: Campañas
    description: Campañas de email.
paths:
  /v1/purchases/stats:
    get:
      tags:
        - Compras
      summary: Agregar compras
      description: >-
        Suma pedidos, ingresos, ticket promedio y clientes únicos con los mismos
        filtros del listado, con ranking opcional por dimensión, incluido UTM.
      operationId: getPurchaseStats
      parameters:
        - $ref: '#/components/parameters/CustomerFilter'
        - $ref: '#/components/parameters/PurchaseStatus'
        - $ref: '#/components/parameters/Platform'
        - $ref: '#/components/parameters/CreatedSince'
        - $ref: '#/components/parameters/CreatedUntil'
        - $ref: '#/components/parameters/MinValue'
        - $ref: '#/components/parameters/MaxValue'
        - $ref: '#/components/parameters/UtmSource'
        - $ref: '#/components/parameters/UtmMedium'
        - $ref: '#/components/parameters/UtmCampaign'
        - $ref: '#/components/parameters/UtmContent'
        - $ref: '#/components/parameters/UtmTerm'
        - $ref: '#/components/parameters/PurchaseStatsGroupBy'
        - $ref: '#/components/parameters/PurchaseStatsGroupLimit'
      responses:
        '200':
          $ref: '#/components/responses/PurchaseStats'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/ValidationError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    CustomerFilter:
      name: customer_id
      in: query
      description: Filtra compras por cliente.
      schema:
        type: string
        pattern: ^cus_[A-Za-z0-9_-]+$
    PurchaseStatus:
      name: status
      in: query
      description: Filtra por el estado financiero de la compra.
      schema:
        type: string
        enum:
          - any
          - pending
          - authorized
          - paid
          - abandoned
          - refunded
          - voided
    Platform:
      name: platform
      in: query
      description: Filtra por la plataforma de origen.
      schema:
        type: string
        enum:
          - nuvemshop
          - shopify
          - woocommerce
          - bling
          - instagram
          - popup
    CreatedSince:
      name: created_since
      in: query
      description: Incluye elementos creados desde este instante, inclusive.
      schema:
        type: string
        format: date-time
    CreatedUntil:
      name: created_until
      in: query
      description: Incluye elementos creados hasta este instante, inclusive.
      schema:
        type: string
        format: date-time
    MinValue:
      name: min_value_in_cents
      in: query
      description: Valor mínimo de la compra en centavos.
      schema:
        type: integer
        minimum: 0
    MaxValue:
      name: max_value_in_cents
      in: query
      description: Valor máximo de la compra en centavos.
      schema:
        type: integer
        minimum: 0
    UtmSource:
      name: utm_source
      in: query
      description: Filtra por el utm_source del pedido.
      schema:
        type: string
        maxLength: 256
    UtmMedium:
      name: utm_medium
      in: query
      description: Filtra por el utm_medium del pedido.
      schema:
        type: string
        maxLength: 256
    UtmCampaign:
      name: utm_campaign
      in: query
      description: Filtra por el utm_campaign del pedido.
      schema:
        type: string
        maxLength: 256
    UtmContent:
      name: utm_content
      in: query
      description: Filtra por el utm_content del pedido.
      schema:
        type: string
        maxLength: 256
    UtmTerm:
      name: utm_term
      in: query
      description: Filtra por el utm_term del pedido.
      schema:
        type: string
        maxLength: 256
    PurchaseStatsGroupBy:
      name: group_by
      in: query
      description: Agrupa el resultado por una dimensión y devuelve su ranking.
      schema:
        type: string
        enum:
          - status
          - platform
          - currency
          - day
          - utm_source
          - utm_medium
          - utm_campaign
          - utm_content
          - utm_term
    PurchaseStatsGroupLimit:
      name: group_limit
      in: query
      description: Cantidad máxima de grupos devueltos.
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 10
  responses:
    PurchaseStats:
      description: Métricas agregadas de compras.
      headers:
        ETag:
          $ref: '#/components/headers/ETag'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PurchaseStats'
    Unauthorized:
      description: Clave API ausente, inválida, expirada o revocada.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: authentication_error
              message: Invalid API key.
              request_id: req_07f6cdc3c20249d6afcd90b4
    ValidationError:
      description: Un parámetro no superó la validación.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: validation_error
              message: Invalid query parameters.
              param: limit
              request_id: req_07f6cdc3c20249d6afcd90b4
    RateLimited:
      description: Límite de solicitudes superado.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitErrorResponse'
    InternalError:
      description: Error inesperado en el servidor.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  headers:
    ETag:
      description: Identificador de la versión del contenido para caché condicional.
      schema:
        type: string
        example: '"v1-4ad31f5efb6b8f35"'
    RetryAfter:
      description: Segundos antes de volver a intentarlo.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: Límite total de la ventana actual.
      schema:
        type: integer
        example: 600
    RateLimitRemaining:
      description: Solicitudes restantes en la ventana actual.
      schema:
        type: integer
        example: 599
    RateLimitReset:
      description: Instante UTC en que termina la ventana actual.
      schema:
        type: string
        format: date-time
  schemas:
    PurchaseStats:
      type: object
      required:
        - object
        - purchase_count
        - customer_count
        - revenue_in_cents
        - average_ticket_in_cents
        - currency
        - mixed_currencies
        - group_by
        - groups
        - groups_truncated
      properties:
        object:
          type: string
          const: purchase_stats
        purchase_count:
          type: integer
          minimum: 0
        customer_count:
          type: integer
          minimum: 0
        revenue_in_cents:
          type: integer
        average_ticket_in_cents:
          type: integer
        currency:
          type:
            - string
            - 'null'
          example: BRL
        mixed_currencies:
          type: boolean
        group_by:
          type:
            - string
            - 'null'
        groups:
          type: array
          items:
            type: object
            required:
              - key
              - purchase_count
              - revenue_in_cents
              - average_ticket_in_cents
            properties:
              key:
                type:
                  - string
                  - 'null'
              purchase_count:
                type: integer
                minimum: 0
              revenue_in_cents:
                type: integer
              average_ticket_in_cents:
                type: integer
        groups_truncated:
          type: boolean
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
    RateLimitErrorResponse:
      allOf:
        - $ref: '#/components/schemas/ErrorResponse'
        - type: object
          required:
            - retry_after
          properties:
            retry_after:
              type: integer
              minimum: 1
              description: Segundos antes de volver a intentarlo.
    Error:
      type: object
      required:
        - type
        - message
        - request_id
      properties:
        type:
          type: string
          enum:
            - authentication_error
            - conflict
            - internal_error
            - invalid_request
            - not_found
            - permission_denied
            - rate_limited
            - validation_error
        message:
          type: string
        param:
          type: string
        request_id:
          type: string
          pattern: ^req_[a-f0-9]{24}$
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: bvt_live_...
      description: Clave API creada en la configuración de la organización.

````