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

# Vista previa de segmento

> Cuenta y muestra una muestra de los clientes que cumplen las condiciones ahora, sin guardar nada, e informa cuántos pueden recibir por WhatsApp y por correo. Los errores indican cada condición inválida con las opciones válidas. Exige una clave API con el permiso read.



## OpenAPI

````yaml /openapi.es.json post /v1/segment-builder/preview
openapi: 3.1.0
info:
  title: API de Bevits
  version: 1.0.0
  description: >-
    API pública para consultar datos de CRM, compras y automatización de una
    organización de Bevits, crear automatizaciones como borrador para revisarlas
    y activarlas, crear campañas de WhatsApp Oficial como borrador y armar
    segmentos y etiquetas de clientes.
  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.
  - name: Cuenta y marca
    description: Contexto de la cuenta, identidad de la marca e imágenes.
  - name: Recetas
    description: Automatizaciones listas creadas a partir de recetas, con deshacer.
  - name: Plantillas de email
    description: Creación e importación de plantillas de correo.
  - name: Eventos
    description: Eventos personalizados enviados por la tienda y sus tipos.
paths:
  /v1/segment-builder/preview:
    post:
      tags:
        - Segmentos
      summary: Vista previa de segmento
      description: >-
        Cuenta y muestra una muestra de los clientes que cumplen las condiciones
        ahora, sin guardar nada, e informa cuántos pueden recibir por WhatsApp y
        por correo. Los errores indican cada condición inválida con las opciones
        válidas. Exige una clave API con el permiso read.
      operationId: previewSegment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SegmentPreviewRequest'
            example:
              match: all
              conditions:
                - kind: coupon
                  status: has_available
                  source: cashback
                  expires_within_days: 7
                - kind: field
                  field: totalSpentInCents
                  operator: gte
                  value: 50000
      responses:
        '200':
          $ref: '#/components/responses/SegmentPreview'
        '400':
          $ref: '#/components/responses/InvalidBody'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ReadScopeRequired'
        '422':
          $ref: '#/components/responses/SegmentValidationError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    SegmentPreviewRequest:
      type: object
      required:
        - conditions
      properties:
        match:
          $ref: '#/components/schemas/SegmentMatch'
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/SegmentCondition'
          minItems: 1
          maxItems: 30
          description: >-
            Condiciones del catálogo de filtros (GET
            /v1/segment-builder/catalog). Hasta 30.
        sample_size:
          type: integer
          minimum: 0
          maximum: 20
          default: 5
          description: Cantidad de clientes en la muestra.
    SegmentMatch:
      type: string
      enum:
        - all
        - any
      description: >-
        all: clientes que cumplen todas las condiciones. any: clientes que
        cumplen al menos una.
    SegmentCondition:
      description: >-
        Una condición de un segmento por filtros. El mismo formato entra en la
        creación, la actualización y la vista previa y vuelve en GET
        /v1/segments/{segment_id}.
      oneOf:
        - $ref: '#/components/schemas/SegmentFieldCondition'
        - $ref: '#/components/schemas/SegmentTagsCondition'
        - $ref: '#/components/schemas/SegmentProductCondition'
        - $ref: '#/components/schemas/SegmentCouponCondition'
      discriminator:
        propertyName: kind
        mapping:
          field: '#/components/schemas/SegmentFieldCondition'
          tags: '#/components/schemas/SegmentTagsCondition'
          product: '#/components/schemas/SegmentProductCondition'
          coupon: '#/components/schemas/SegmentCouponCondition'
    SegmentPreview:
      type: object
      required:
        - object
        - customer_count
        - whatsapp_reachable_count
        - email_reachable_count
        - match
        - conditions
        - sample
        - evaluated_at
      properties:
        object:
          type: string
          const: segment_preview
        customer_count:
          type: integer
          minimum: 0
        whatsapp_reachable_count:
          type: integer
          minimum: 0
          description: Clientes que cumplen las condiciones, con teléfono y sin opt-out.
        email_reachable_count:
          type: integer
          minimum: 0
          description: >-
            Clientes que cumplen las condiciones, con correo y suscritos para
            recibir correos.
        match:
          $ref: '#/components/schemas/SegmentMatch'
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/SegmentCondition'
        sample:
          type: array
          items:
            $ref: '#/components/schemas/SegmentSampleCustomer'
        evaluated_at:
          type: string
          format: date-time
    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.
    SegmentFieldCondition:
      type: object
      additionalProperties: false
      required:
        - kind
        - field
        - operator
      properties:
        kind:
          type: string
          const: field
        field:
          type: string
          minLength: 1
          maxLength: 256
          description: >-
            Un campo del cliente (como totalSpentInCents, lastPurchaseDate o
            city) o el ID de un atributo personalizado (atr_...), del catálogo
            de filtros.
        operator:
          type: string
          minLength: 1
          maxLength: 32
          description: >-
            Uno de los operadores del campo en el catálogo. Texto: eq, neq, in,
            not_in, contains, not_contains, starts_with, is_null, is_not_null.
            Número: eq, neq, gt, gte, lt, lte. Booleano: eq_true, eq_false,
            is_null, is_not_null. Fecha: gt, lt, between.
        value:
          description: >-
            Omítelo en is_null, is_not_null, eq_true y eq_false. Una lista en in
            y not_in. Dinero en centavos. Fechas en ISO 8601 con zona horaria.
          oneOf:
            - type: string
              maxLength: 512
            - type: number
            - type: boolean
            - type: array
              items:
                type: string
                minLength: 1
                maxLength: 256
              minItems: 1
              maxItems: 500
        value_to:
          description: Fin de un intervalo between.
          oneOf:
            - type: string
              maxLength: 64
            - type: number
    SegmentTagsCondition:
      type: object
      additionalProperties: false
      required:
        - kind
        - operator
        - tag_ids
      properties:
        kind:
          type: string
          const: tags
        operator:
          type: string
          enum:
            - has_any
            - has_all
            - has_none
          description: >-
            has_any: tiene alguna de las etiquetas. has_all: tiene todas.
            has_none: no tiene ninguna, incluso quienes no tienen etiquetas.
        tag_ids:
          type: array
          items:
            type: string
            pattern: ^tag_[A-Za-z0-9_-]+$
          minItems: 1
          maxItems: 50
          description: IDs de las etiquetas (tag_...), de GET /v1/tags.
    SegmentProductCondition:
      type: object
      additionalProperties: false
      required:
        - kind
        - operator
      properties:
        kind:
          type: string
          const: product
        operator:
          type: string
          enum:
            - has_purchased
            - has_not_purchased
            - purchased_in_category
        product_id:
          type: string
          minLength: 1
          maxLength: 256
          description: >-
            ID del producto en la tienda, como en los artículos de las compras.
            Para has_purchased y has_not_purchased.
        category:
          type: string
          minLength: 1
          maxLength: 256
          description: Nombre de la categoría del producto. Para purchased_in_category.
    SegmentCouponCondition:
      type: object
      additionalProperties: false
      required:
        - kind
        - status
      description: >-
        Cupones y cashback (giftback) que Bevits generó para el cliente en las
        automatizaciones, en la atención con IA y en las ventas de las tiendas
        físicas.
      properties:
        kind:
          type: string
          const: coupon
        status:
          type: string
          enum:
            - has_available
            - has_unused
            - has_expired_unused
            - has_used
            - has_received
            - has_not_received
          description: >-
            has_available: tiene un cupón sin usar y vigente, con saldo para
            usar ahora. has_unused: tiene un cupón que nunca usó, vencido o no.
            has_expired_unused: dejó vencer un cupón sin usarlo. has_used: usó
            un cupón en una compra. has_received: recibió un cupón.
            has_not_received: nunca recibió un cupón.
        source:
          type: string
          enum:
            - cashback
            - any
            - flows
          default: cashback
          description: >-
            cashback: cupones generados por una compra (cashback o giftback,
            online o en la tienda física). any: todos los cupones que Bevits
            generó para el cliente. flows: solo los cupones de las
            automatizaciones en flow_ids.
        flow_ids:
          type: array
          items:
            type: string
            pattern: ^flw_[A-Za-z0-9_-]+$
          minItems: 1
          maxItems: 50
          description: >-
            Con source flows: automatizaciones que generan cupones, listadas en
            el catálogo.
        received_within_days:
          type: integer
          minimum: 1
          maximum: 3650
          description: Solo cupones generados en los últimos N días.
        expires_within_days:
          type: integer
          minimum: 1
          maximum: 365
          description: 'Con has_available: solo cupones que vencen en los próximos N días.'
    SegmentSampleCustomer:
      type: object
      required:
        - object
        - id
      properties:
        object:
          type: string
          const: customer
        id:
          type: string
          pattern: ^cus_[A-Za-z0-9_-]+$
        name:
          type: string
        email:
          type: string
        phone:
          type: string
    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
        code:
          type: string
          description: >-
            Motivo estable y legible por máquina dentro de type, como
            invalid_event_name. Presente cuando el error tiene un motivo con
            nombre.
        message:
          type: string
        param:
          type: string
          description: >-
            Ruta completa del campo con problema, como customer.email o
            events[3].name.
        suggestion:
          type: string
          description: Un valor que sería aceptado, cuando existe uno obvio.
        request_id:
          type: string
          pattern: ^req_[a-f0-9]{24}$
  responses:
    SegmentPreview:
      description: Vista previa del segmento. No se guardó nada.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SegmentPreview'
    InvalidBody:
      description: >-
        Cuerpo de la solicitud ausente, que no es un objeto JSON, o parámetro de
        ruta inválido.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    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
    ReadScopeRequired:
      description: >-
        La clave API no tiene el permiso read. Es el caso de una clave solo de
        envío, creada únicamente con events:write.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              type: permission_denied
              code: missing_scope
              message: This API key does not have the required "read" scope.
              param: scope
              request_id: req_07f6cdc3c20249d6afcd90b4
    SegmentValidationError:
      description: >-
        Alguna condición o campo fue rechazado, por ejemplo un operador que no
        aplica al campo o un segmento RFM. El mensaje dice qué corregir y las
        opciones válidas, y error.param indica el campo.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    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:
    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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: bvt_live_...
      description: Clave API creada en la configuración de la organización.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.