> ## 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.

# Aggregate purchases

> Sums orders, revenue, average ticket, and unique customers using the same filters as the listing, with optional ranking by dimension, including UTM.



## OpenAPI

````yaml /openapi.en.json get /v1/purchases/stats
openapi: 3.1.0
info:
  title: Bevits API
  version: 1.0.0
  description: >-
    Public read-only API for querying CRM, purchase, and automation data from a
    Bevits organization.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.bevits.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: System
    description: API availability.
  - name: Identity
    description: Organization and API key identity.
  - name: Customers
    description: Customers and their relationships.
  - name: Segments
    description: Customer segments.
  - name: Purchases
    description: Purchases imported from integrations.
  - name: CRM data
    description: Tags and attribute definitions.
  - name: Automations
    description: Automation flows.
  - name: Campaigns
    description: Email campaigns.
paths:
  /v1/purchases/stats:
    get:
      tags:
        - Purchases
      summary: Aggregate purchases
      description: >-
        Sums orders, revenue, average ticket, and unique customers using the
        same filters as the listing, with optional ranking by dimension,
        including 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: Filters purchases by customer.
      schema:
        type: string
        pattern: ^cus_[A-Za-z0-9_-]+$
    PurchaseStatus:
      name: status
      in: query
      description: Filters by purchase payment status.
      schema:
        type: string
        enum:
          - any
          - pending
          - authorized
          - paid
          - abandoned
          - refunded
          - voided
    Platform:
      name: platform
      in: query
      description: Filters by source platform.
      schema:
        type: string
        enum:
          - nuvemshop
          - shopify
          - woocommerce
          - bling
          - instagram
          - popup
    CreatedSince:
      name: created_since
      in: query
      description: Includes items created at or after this instant.
      schema:
        type: string
        format: date-time
    CreatedUntil:
      name: created_until
      in: query
      description: Includes items created at or before this instant.
      schema:
        type: string
        format: date-time
    MinValue:
      name: min_value_in_cents
      in: query
      description: Minimum purchase amount in cents.
      schema:
        type: integer
        minimum: 0
    MaxValue:
      name: max_value_in_cents
      in: query
      description: Maximum purchase amount in cents.
      schema:
        type: integer
        minimum: 0
    UtmSource:
      name: utm_source
      in: query
      description: Filters by the order's utm_source.
      schema:
        type: string
        maxLength: 256
    UtmMedium:
      name: utm_medium
      in: query
      description: Filters by the order's utm_medium.
      schema:
        type: string
        maxLength: 256
    UtmCampaign:
      name: utm_campaign
      in: query
      description: Filters by the order's utm_campaign.
      schema:
        type: string
        maxLength: 256
    UtmContent:
      name: utm_content
      in: query
      description: Filters by the order's utm_content.
      schema:
        type: string
        maxLength: 256
    UtmTerm:
      name: utm_term
      in: query
      description: Filters by the order's utm_term.
      schema:
        type: string
        maxLength: 256
    PurchaseStatsGroupBy:
      name: group_by
      in: query
      description: Groups the result by a dimension and returns its 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: Maximum number of groups returned.
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 10
  responses:
    PurchaseStats:
      description: Aggregated purchase metrics.
      headers:
        ETag:
          $ref: '#/components/headers/ETag'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PurchaseStats'
    Unauthorized:
      description: Missing, invalid, expired, or revoked API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: authentication_error
              message: Invalid API key.
              request_id: req_07f6cdc3c20249d6afcd90b4
    ValidationError:
      description: A parameter failed validation.
      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: Request limit exceeded.
      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: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  headers:
    ETag:
      description: Content version identifier for conditional caching.
      schema:
        type: string
        example: '"v1-4ad31f5efb6b8f35"'
    RetryAfter:
      description: Seconds before retrying.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: Total limit for the current window.
      schema:
        type: integer
        example: 600
    RateLimitRemaining:
      description: Requests remaining in the current window.
      schema:
        type: integer
        example: 599
    RateLimitReset:
      description: UTC instant when the current window ends.
      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: Seconds before retrying.
    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: API key created in the organization settings.

````