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

# Run an analytics query for the active agency.



## OpenAPI

````yaml https://megastream25-api.closebot.com/swagger/v1/swagger.json post /analytics/query
openapi: 3.0.4
info:
  title: CloseBot API
  version: v1
servers:
  - url: https://api.closebot.com
    description: CloseBot API Endpoint
security:
  - Key: []
tags:
  - name: Account
  - name: AccountNotification
  - name: Agency
  - name: Analytics
  - name: Billing
  - name: Bot
  - name: BotMetric
  - name: BotSourceVariable
  - name: BotTemplate
  - name: BotTesting
  - name: Dashboard
  - name: Hierarchy
  - name: Lead
  - name: Leaderboard
  - name: Library
  - name: LiveDemo
  - name: Notification
  - name: Persona
  - name: Report
  - name: SmartFAQ
  - name: Source
  - name: SourceChannel
  - name: Webhook
paths:
  /analytics/query:
    post:
      tags:
        - Analytics
      summary: Run an analytics query for the active agency.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnalyticsQueryRequest'
          text/json:
            schema:
              $ref: '#/components/schemas/AnalyticsQueryRequest'
          application/*+json:
            schema:
              $ref: '#/components/schemas/AnalyticsQueryRequest'
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/AnalyticsQueryResponse'
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyticsQueryResponse'
            text/json:
              schema:
                $ref: '#/components/schemas/AnalyticsQueryResponse'
components:
  schemas:
    AnalyticsQueryRequest:
      required:
        - end
        - metric
        - resolution
        - start
      type: object
      properties:
        metric:
          type: string
          description: >-
            Metric to query. Call GET /analytics/metrics for the full catalog of
            valid keys,

            or pass "formula" together with
            Closebot.Api.Controllers.AnalyticsController.AnalyticsQueryRequest.Formula
            to compute a derived metric.
          nullable: true
        formula:
          $ref: '#/components/schemas/AnalyticsFormulaRequest'
        start:
          type: string
          description: >-
            Inclusive start. A UTC instant in utc mode; a source-local
            wall-clock value in

            sourceLocal mode. Must align to a 15-minute boundary.
          format: date-time
        end:
          type: string
          description: >-
            Exclusive end. A UTC instant in utc mode; a source-local wall-clock
            value in

            sourceLocal mode. Must align to a 15-minute boundary.
          format: date-time
        resolution:
          type: string
          description: >-
            Bucket size. Time buckets: 15m, hour, day, week, month (multiples of
            the 15-minute base).

            Week buckets start Monday 00:00 of the active time basis.

            Non-time: source (one point per source name over the whole range,
            not grouped by time),

            total (the whole range as one point), hourOfWeek (every bucket
            folded onto one week of

            day-of-week x hour-of-day cells).
          nullable: true
        groupBy:
          type: array
          items:
            type: string
          description: >-
            Optional dimension to split the series by — source, channel, bot,
            persona, or the

            metric's own detail dimensions. At most one: a chart segments by a
            single thing, and

            allowing two would multiply the series out past anything readable.
          nullable: true
        timeZone:
          type: string
          description: >-
            IANA time zone id (e.g. "America/Denver") used by the hourOfWeek
            fold when

            Closebot.Api.Controllers.AnalyticsController.AnalyticsQueryRequest.TimeBasis
            is utc, to decide which local weekday and hour each bucket

            belongs to. Ignored by every other resolution, and ignored entirely
            in sourceLocal

            mode — that fold reads each row's own source-local timestamp
            instead. Defaults to UTC.
          nullable: true
        timeBasis:
          type: string
          description: >-
            "utc" (default) or "sourceLocal". See
            Closebot.Api.Controllers.AnalyticsController.AnalyticsTimeBasis.

            In sourceLocal mode
            Closebot.Api.Controllers.AnalyticsController.AnalyticsQueryRequest.Start
            and
            Closebot.Api.Controllers.AnalyticsController.AnalyticsQueryRequest.End
            are read as

            wall-clock values rather than UTC instants, so a month means each
            source's own

            local month.
          nullable: true
        filters:
          $ref: '#/components/schemas/AnalyticsQueryFilters'
      additionalProperties: false
    AnalyticsQueryResponse:
      required:
        - points
      type: object
      properties:
        points:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsQueryPoint'
          nullable: true
        sourcesMissingTimeZone:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsMissingTimeZoneSource'
          description: >-
            Sources that contributed rows to this result but have no resolvable
            timezone, so

            were bucketed as UTC. Populated only in sourceLocal mode; null
            otherwise.

            Lets the chart say which sources need fixing instead of being
            quietly wrong.
          nullable: true
      additionalProperties: false
    AnalyticsFormulaRequest:
      required:
        - expression
      type: object
      properties:
        expression:
          type: string
          description: >-
            Arithmetic over catalog metrics, with operands in square brackets —
            for example

            `([aiResponses] / [bookings]) * 100`. Supports + - * / and
            parentheses.
          nullable: true
      additionalProperties: false
    AnalyticsQueryFilters:
      type: object
      properties:
        sourceIds:
          type: array
          items:
            type: string
          description: Optional AgencySource IDs to include.
          nullable: true
        dimensions:
          type: array
          items:
            $ref: '#/components/schemas/DimensionFilter'
          description: >-
            Optional narrowing by the metric's declared dimensions. Each entry
            ANDs with the rest.

            A dimension the metric does not declare is a 400 rather than a
            silent no-op — a chart

            must never quietly show unfiltered totals under a filter the user
            set.
          nullable: true
      additionalProperties: false
    AnalyticsQueryPoint:
      required:
        - timestamp
        - value
      type: object
      properties:
        timestamp:
          type: string
          description: >-
            Start of the bucket. A UTC instant in utc mode; a local wall-clock
            value with no

            zone (and therefore no trailing Z) in sourceLocal mode.
          format: date-time
        value:
          type: number
          description: >-
            Bucket value. Decimal because metrics can be currency, durations or
            averages;

            count metrics still come back as whole numbers.
          format: double
        group:
          type: object
          additionalProperties:
            type: string
          description: >-
            Present when groupBy is set, or when resolution is a non-time
            dimension.

            Carries the dimension's raw value plus a display label under
            "<dimension>Label",

            so the chart legend does not have to know how to render a channel
            key or a bot id.
          nullable: true
      additionalProperties: false
    AnalyticsMissingTimeZoneSource:
      required:
        - sourceId
        - sourceName
      type: object
      properties:
        sourceId:
          type: string
          nullable: true
        sourceName:
          type: string
          nullable: true
      additionalProperties: false
      description: >-
        A source whose rows had to be bucketed as UTC because it has no usable
        zone.
    DimensionFilter:
      required:
        - dimension
        - operator
      type: object
      properties:
        dimension:
          type: string
          description: >-
            One of
            Closebot.Api.Controllers.AnalyticsController.MetricDimensions. Must
            be declared by the metric.
          nullable: true
        operator:
          type: string
          description: >-
            One of
            Closebot.Api.Controllers.AnalyticsController.DimensionOperators.
          nullable: true
        values:
          type: array
          items:
            type: string
          description: Required for `is` and `isNot`; ignored otherwise.
          nullable: true
      additionalProperties: false
      description: One filter on one dimension.
  securitySchemes:
    Key:
      type: apiKey
      description: CloseBot API Key Authorization
      name: X-CB-KEY
      in: header

````