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

# Preview a cohort rule

> Runs a `rules` document without saving it and reports what it would select, which is how you check a rule before creating or updating a cohort. The response `data` carries `count` and a `sample` of matching customers. A rule document the API cannot read returns 422.



## OpenAPI

````yaml /openapi/kintra-app.json post /tenant/{tenantId}/cohorts/preview
openapi: 3.0.0
info:
  description: >-
    Tenant portal API for the Kintra loyalty platform. Requests are
    authenticated with an Auth0 bearer token and address a tenant by id in the
    path.
  title: Kintra Portal API
  version: 1.0.0
servers:
  - description: Production environment
    url: https://api.kintra.io/api/v1
security: []
paths:
  /tenant/{tenantId}/cohorts/preview:
    post:
      tags:
        - Cohorts
      summary: Preview a cohort rule
      description: >-
        Runs a `rules` document without saving it and reports what it would
        select, which is how you check a rule before creating or updating a
        cohort. The response `data` carries `count` and a `sample` of matching
        customers. A rule document the API cannot read returns 422.
      operationId: PreviewCohort
      parameters:
        - in: path
          name: tenantId
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              properties:
                rules:
                  $ref: '#/components/schemas/CohortRuleDocumentDto'
              required:
                - rules
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_CohortPreviewResponse_'
          description: ''
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_null_'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_null_'
          description: Feature disabled or insufficient permissions
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_null_'
          description: Tenant not found
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_null_'
          description: Invalid rule set
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse_null_'
          description: Internal server error
      security:
        - auth0_jwt: []
components:
  schemas:
    CohortRuleDocumentDto:
      additionalProperties: false
      description: >-
        TSOA-friendly rule document DTO. Cast to CohortRuleDocument at service
        boundary.
      properties:
        operator:
          enum:
            - and
          nullable: false
          type: string
        predicates:
          items:
            $ref: '#/components/schemas/AttributePredicateDto'
          type: array
        version:
          enum:
            - 1
          nullable: false
          type: number
      required:
        - version
        - operator
        - predicates
      type: object
    ApiResponse_CohortPreviewResponse_:
      additionalProperties: false
      properties:
        data:
          $ref: '#/components/schemas/CohortPreviewResponse'
        errors:
          items:
            properties:
              message:
                type: string
              path:
                type: string
            required:
              - path
              - message
            type: object
          type: array
        message:
          type: string
        success:
          type: boolean
      required:
        - success
      type: object
    ApiResponse_null_:
      additionalProperties: false
      properties:
        data:
          enum:
            - null
          nullable: true
          type: number
        errors:
          items:
            properties:
              message:
                type: string
              path:
                type: string
            required:
              - path
              - message
            type: object
          type: array
        message:
          type: string
        success:
          type: boolean
      required:
        - success
      type: object
    AttributePredicateDto:
      additionalProperties: false
      description: >-
        TSOA-friendly predicate DTO (no tuple types — TSOA rejects TypeScript
        tuples).
      properties:
        key:
          type: string
        op:
          type: string
        type:
          enum:
            - attribute
          nullable: false
          type: string
        value:
          anyOf:
            - type: string
            - format: double
              type: number
            - items:
                anyOf:
                  - type: string
                  - format: double
                    type: number
              type: array
      required:
        - type
        - key
        - op
        - value
      type: object
    CohortPreviewResponse:
      additionalProperties: false
      properties:
        count:
          format: double
          type: number
        sample:
          items:
            $ref: '#/components/schemas/ICustomerProfileResponse'
          type: array
      required:
        - count
        - sample
      type: object
    ICustomerProfileResponse:
      additionalProperties: false
      properties:
        tenant:
          description: >-
            Current tenant label; present for authenticated customer profile
            reads.
          properties:
            id:
              type: string
            name:
              type: string
            slug:
              type: string
          required:
            - slug
            - name
            - id
          type: object
        user:
          allOf:
            - $ref: '#/components/schemas/IUserProfileResponse'
            - properties:
                clubs:
                  items:
                    $ref: '#/components/schemas/IClubResponse'
                  nullable: true
                  type: array
                cohort_metadata:
                  allOf:
                    - $ref: '#/components/schemas/Record_string.unknown_'
                  nullable: true
                country:
                  allOf:
                    - $ref: '#/components/schemas/ICountryResponse'
                  nullable: true
                xp_status:
                  anyOf:
                    - $ref: '#/components/schemas/XpStatus'
                    - type: string
                  nullable: true
              type: object
      required:
        - user
      type: object
    IUserProfileResponse:
      additionalProperties: false
      properties:
        auth_provider:
          type: string
        auth_provider_id:
          type: string
        created_at:
          format: date-time
          nullable: true
          type: string
        email:
          type: string
        first_name:
          nullable: true
          type: string
        id:
          type: string
        internal_wallets:
          items:
            $ref: '#/components/schemas/IInternalWalletResponse'
          type: array
        last_name:
          nullable: true
          type: string
        onboarding_status:
          anyOf:
            - $ref: '#/components/schemas/UserOnboardingStatus'
            - type: string
        onboarding_type:
          anyOf:
            - $ref: '#/components/schemas/UserOnboardingType'
            - type: string
          nullable: true
        status:
          type: string
        updated_at:
          format: date-time
          nullable: true
          type: string
        username:
          type: string
      required:
        - id
        - username
        - email
        - auth_provider
        - auth_provider_id
        - status
        - onboarding_status
      type: object
    IClubResponse:
      additionalProperties: false
      description: JSON response for a row in `core.clubs`.
      properties:
        country_id:
          nullable: true
          type: string
        icon_url:
          nullable: true
          type: string
        id:
          type: string
        name:
          type: string
        slug:
          type: string
        sport_id:
          nullable: true
          type: string
        status:
          anyOf:
            - $ref: '#/components/schemas/ClubStatus'
            - type: string
      required:
        - id
        - name
        - slug
        - sport_id
        - country_id
        - icon_url
        - status
      type: object
    Record_string.unknown_:
      additionalProperties: {}
      description: Construct a type with a set of properties K of type T
      properties: {}
      type: object
    ICountryResponse:
      additionalProperties: false
      description: JSON response for a row in `core.countries`.
      properties:
        code:
          nullable: true
          type: string
        icon_url:
          nullable: true
          type: string
        id:
          type: string
        name:
          type: string
        status:
          anyOf:
            - $ref: '#/components/schemas/CountryStatus'
            - type: string
      required:
        - id
        - name
        - code
        - icon_url
        - status
      type: object
    XpStatus:
      enum:
        - active
        - locked
      type: string
    IInternalWalletResponse:
      additionalProperties: false
      properties:
        address:
          type: string
        created_at:
          format: date-time
          type: string
        deleted_at:
          format: date-time
          nullable: true
          type: string
        id:
          type: string
        label:
          nullable: true
          type: string
        updated_at:
          format: date-time
          type: string
        user_id:
          type: string
        wallet_kind:
          type: string
      required:
        - id
        - address
        - wallet_kind
        - user_id
      type: object
    UserOnboardingStatus:
      enum:
        - initial
        - registered
        - active
      type: string
    UserOnboardingType:
      enum:
        - admin
        - tenant
        - user
      type: string
    ClubStatus:
      description: Lifecycle status for reference rows in `core.clubs`.
      enum:
        - active
        - inactive
      type: string
    CountryStatus:
      description: Lifecycle status for reference rows in `core.countries`.
      enum:
        - active
        - inactive
      type: string
  securitySchemes:
    auth0_jwt:
      bearerFormat: JWT
      description: Auth0 access token
      scheme: bearer
      type: http

````