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

# Top clients by revenue

> Powers the **Top clients by revenue** progress-bar list on the **Sales analytics** screen.

Ranked by `total_contracted_revenue` descending. `revenue_share_pct` is each client's share of total period revenue, computed as a window function so it always sums to 100% across the returned rows.



## OpenAPI

````yaml /openapi/commercial.yaml get /api/v1/analytics/sales/top-clients
openapi: 3.0.3
info:
  title: Commercial Service API
  version: 1.0.0
  description: |2-

        **Commercial Service API** - Lead management and campaign workflow system.

        ## Versioning
        The API uses URL path versioning (e.g., `/api/v1/`, `/api/v2/`).
        Current version: **v1**
        
servers:
  - url: https://api.capedigital.co.ke/commercial
    description: Production
  - url: http://localhost:8000
    description: Local
security: []
paths:
  /api/v1/analytics/sales/top-clients:
    get:
      tags:
        - Sales Analytics
      summary: Top clients by revenue
      description: >-
        Powers the **Top clients by revenue** progress-bar list on the **Sales
        analytics** screen.


        Ranked by `total_contracted_revenue` descending. `revenue_share_pct` is
        each client's share of total period revenue, computed as a window
        function so it always sums to 100% across the returned rows.
      operationId: analytics_sales_top_clients_list
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
          description: Max rows to return. Clamped to 1–50. Default 10.
        - in: query
          name: period
          schema:
            type: string
          description: |-
            Period string. Accepted formats:
            - `2026-05` — calendar month
            - `Q2-2026` — quarter (Q1–Q4)
            - `YTD-2026` — year to date
          required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TopClient'
              examples:
                May2026Top3:
                  value:
                    - - client_name: Safaricom
                        category: Direct
                        total_contracted_revenue: '2400000.00'
                        deal_count: 3
                        revenue_share_pct: '11.2'
                      - client_name: KCB Bank
                        category: Direct
                        total_contracted_revenue: '1900000.00'
                        deal_count: 2
                        revenue_share_pct: '8.9'
                      - client_name: Equity Group
                        category: Direct
                        total_contracted_revenue: '1500000.00'
                        deal_count: 2
                        revenue_share_pct: '7.0'
                  summary: May 2026 top 3
          description: ''
      security:
        - bearerAuth: []
components:
  schemas:
    TopClient:
      type: object
      properties:
        client_name:
          type: string
        category:
          type: string
        total_contracted_revenue:
          type: string
          format: decimal
          pattern: ^-?\d{0,16}(?:\.\d{0,2})?$
        deal_count:
          type: integer
        revenue_share_pct:
          type: string
          format: decimal
          pattern: ^-?\d{0,4}(?:\.\d{0,1})?$
      required:
        - category
        - client_name
        - deal_count
        - revenue_share_pct
        - total_contracted_revenue
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Enter your JWT token in the format: Bearer <token>'

````