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

# Report the customer base by RFM segment (segment client)

> Computes an RFM (Recency / Frequency / Monetary) segmentation over the whole customer base and returns the per-bucket population plus the individual customer rows. Reach for this to answer 'who should I target' or 'how healthy is the base'; use `listCustomers` when you just need the directory. Buckets: `champions` (recent, frequent, high value), `loyal`, `at_risk` (was good, has gone quiet), `new` (never purchased) and `lost`. The optional `segment` / `tier` / `minMonetaryCents` facets are the saved-segment predicate: they narrow the returned `customers` rows ONLY — `total` and `counts` always describe the whole base, so a bucket keeps its true size. `monetaryCents` is integer cents; `recencyDays` is null for a customer who never bought. Feed the same facets to `createCampaign` to target this audience. Note each row carries the customer's raw `email`/`phone`, so this returns contact details for the whole base — narrow it with the facets rather than pulling everything.



## OpenAPI

````yaml /openapi.json get /v1/customers/segments
openapi: 3.0.3
info:
  title: Solya POS API
  version: 1.0.0
  description: >-
    The Solya POS backend HTTP surface. Every documented operation is
    agent-ready: it carries an `operationId`, an agent-facing `description`, the
    `pos.*` scopes it enforces (`x-required-permissions`) and an `x-agent-tier`.
    Success responses return the payload as raw JSON; failures return the
    `ErrorResponse` envelope (`{ error: { code, message, statusCode } }`).
servers:
  - url: /
    description: The backend, relative to its deployed origin.
security: []
paths:
  /v1/customers/segments:
    get:
      tags:
        - Customers
      summary: Report the customer base by RFM segment (segment client)
      description: >-
        Computes an RFM (Recency / Frequency / Monetary) segmentation over the
        whole customer base and returns the per-bucket population plus the
        individual customer rows. Reach for this to answer 'who should I target'
        or 'how healthy is the base'; use `listCustomers` when you just need the
        directory. Buckets: `champions` (recent, frequent, high value), `loyal`,
        `at_risk` (was good, has gone quiet), `new` (never purchased) and
        `lost`. The optional `segment` / `tier` / `minMonetaryCents` facets are
        the saved-segment predicate: they narrow the returned `customers` rows
        ONLY — `total` and `counts` always describe the whole base, so a bucket
        keeps its true size. `monetaryCents` is integer cents; `recencyDays` is
        null for a customer who never bought. Feed the same facets to
        `createCampaign` to target this audience. Note each row carries the
        customer's raw `email`/`phone`, so this returns contact details for the
        whole base — narrow it with the facets rather than pulling everything.
      operationId: getCustomerSegmentation
      parameters:
        - schema:
            type: string
            enum:
              - champions
              - loyal
              - at_risk
              - new
              - lost
          in: query
          name: segment
          required: false
          description: >-
            Restrict the returned rows to one RFM bucket (segment client), e.g.
            `champions`.
        - schema:
            type: string
            minLength: 1
          in: query
          name: tier
          required: false
          description: Restrict the returned rows to one loyalty-tier label, e.g. `Or`.
        - schema:
            type: integer
            minimum: 0
            maximum: 9007199254740991
          in: query
          name: minMonetaryCents
          required: false
          description: >-
            Restrict the returned rows to customers at or above this lifetime
            spend, in cents.
      responses:
        '200':
          description: Whole-base per-segment counts plus the (optionally filtered) rows.
          content:
            application/json:
              schema:
                type: object
                properties:
                  referenceDate:
                    type: string
                  total:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  counts:
                    type: object
                    properties:
                      champions:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      loyal:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      at_risk:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      new:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                      lost:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                    required:
                      - champions
                      - loyal
                      - at_risk
                      - new
                      - lost
                    additionalProperties: false
                  customers:
                    type: array
                    items:
                      type: object
                      properties:
                        customerId:
                          type: string
                        name:
                          type: string
                        email:
                          nullable: true
                          type: string
                        phone:
                          nullable: true
                          type: string
                        tier:
                          type: string
                        optIn:
                          type: boolean
                        metrics:
                          type: object
                          properties:
                            recencyDays:
                              nullable: true
                              type: number
                            frequency:
                              type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                            monetaryCents:
                              type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                          required:
                            - recencyDays
                            - frequency
                            - monetaryCents
                          additionalProperties: false
                        scores:
                          type: object
                          properties:
                            recency:
                              type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                            frequency:
                              type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                            monetary:
                              type: integer
                              minimum: -9007199254740991
                              maximum: 9007199254740991
                          required:
                            - recency
                            - frequency
                            - monetary
                          additionalProperties: false
                        segment:
                          type: string
                          enum:
                            - champions
                            - loyal
                            - at_risk
                            - new
                            - lost
                      required:
                        - customerId
                        - name
                        - email
                        - phone
                        - tier
                        - optIn
                        - metrics
                        - scores
                        - segment
                      additionalProperties: false
                required:
                  - referenceDate
                  - total
                  - counts
                  - customers
                additionalProperties: false
                description: >-
                  Whole-base per-segment counts plus the (optionally filtered)
                  rows.
                example:
                  referenceDate: '2026-07-28T09:00:00.000Z'
                  total: 15
                  counts:
                    champions: 2
                    loyal: 3
                    at_risk: 1
                    new: 8
                    lost: 1
                  customers:
                    - customerId: cust-1
                      name: Camille Renard
                      email: camille.renard@example.com
                      phone: null
                      tier: Or
                      optIn: true
                      metrics:
                        recencyDays: 14
                        frequency: 17
                        monetaryCents: 84250
                      scores:
                        recency: 5
                        frequency: 5
                        monetary: 5
                      segment: champions
        '400':
          description: >-
            The request failed schema validation; `error.fieldErrors` lists the
            fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
        '401':
          description: No valid credential was presented — send a bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: The actor is authenticated but lacks the required `pos.*` scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: An unexpected server error — safe to retry idempotent requests.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  schemas:
    ValidationErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: >-
        A `VALIDATION_FAILED` envelope carrying the offending fields in
        `fieldErrors`.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
            message:
              type: string
            statusCode:
              type: integer
            fieldErrors:
              type: array
              description: >-
                One entry per rejected field: the field path and why it was
                rejected.
              items:
                type: object
                required:
                  - field
                  - message
                additionalProperties: false
                properties:
                  field:
                    type: string
                    description: Dot-path of the offending field.
                  message:
                    type: string
                    description: Why the field was rejected.
    ErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: The uniform failure envelope every non-2xx response returns.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - CONFLICT
                - BUSINESS_RULE_VIOLATION
                - INTERNAL_ERROR
              description: >-
                Machine-readable kernel `ResultCode` — branch on this, not on
                `message`.
            message:
              type: string
              description: >-
                Human-readable explanation. Safe to surface; never leaks server
                internals.
            statusCode:
              type: integer
              description: >-
                The HTTP status, mirrored into the body so a client need not
                read headers.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        `Authorization: Bearer <token>`. Accepts EITHER a Keycloak access token
        (scopes-in-token) OR an opaque POS session token; both resolve to the
        same `pos.*` scope vocabulary the route guards enforce.

````