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

# POST /analytics/query

> Query analytics using the metrics DSL (beta)



## OpenAPI

````yaml /api/openapi/admin-api.json post /analytics/query
openapi: 3.1.0
info:
  description: Admin API for Fanfare
  title: Fanfare Admin API
  version: 1.0.0
servers:
  - description: Production
    url: https://admin.fanfare.io/api
  - description: Local development
    url: http://localhost:4800
security:
  - SecretKeyAuth: []
paths:
  /analytics/query:
    post:
      tags:
        - Analytics
      description: Query analytics using the metrics DSL (beta)
      operationId: postAnalyticsQuery
      requestBody:
        content:
          application/json:
            schema:
              properties:
                groupBy:
                  properties:
                    field:
                      enum:
                        - segment_rfm
                      type: string
                  required:
                    - field
                  type: object
                interval:
                  enum:
                    - 1m
                    - 5m
                    - 10m
                    - 15m
                    - 30m
                    - 1h
                    - 6h
                    - 12h
                    - 1d
                  type: string
                measures:
                  items:
                    properties:
                      event:
                        enum:
                          - pageView
                          - productImpression
                          - productClick
                          - productView
                          - searchSubmitted
                          - addToCart
                          - removeFromCart
                          - viewCart
                          - beginCheckout
                          - purchase
                          - qrScanned
                          - messageClicked
                          - messageOpened
                          - messageRead
                          - messageSent
                          - messageDelivered
                          - messageBounced
                          - messageComplained
                          - messageFailed
                          - queue_entered
                          - queue_admitted
                          - queue_denied
                          - queue_left
                          - queue_completed
                          - draw_entered
                          - draw_won
                          - draw_completed
                          - draw_denied
                          - auction_entered
                          - bid_placed
                          - outbid
                          - bid_won
                          - bid_lost
                          - auction_ended
                          - price_dropped
                          - waitlist_entered
                          - waitlist_left
                          - waitlist_notified
                          - waitlist_expired
                          - waitlist_reordered
                          - timed_release_entered
                          - timed_release_completed
                          - timed_release_left
                          - timed_release_denied
                          - appointment_booked
                          - appointment_confirmed
                          - appointment_reminder
                          - appointment_checked_in
                          - appointment_completed
                          - appointment_cancelled
                          - appointment_rescheduled
                          - appointment_no_show
                          - order_created
                          - order_cancelled
                          - order_refunded
                        type: string
                      field:
                        type: string
                      name:
                        type: string
                      op:
                        enum:
                          - count
                          - sum
                          - avg
                        type: string
                      unit:
                        enum:
                          - count
                          - currency
                        type: string
                    required:
                      - name
                      - unit
                      - op
                      - event
                    type: object
                  type: array
                timeRange:
                  type: string
                where:
                  items:
                    properties:
                      op:
                        enum:
                          - '='
                          - '!='
                          - in
                          - eq
                          - neq
                        type: string
                      path:
                        type: string
                      value: {}
                    required:
                      - path
                      - op
                      - value
                    type: object
                  type: array
              required:
                - interval
                - timeRange
                - measures
              type: object
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  data:
                    items:
                      properties:
                        segment_rfm:
                          type: string
                        series:
                          additionalProperties:
                            anyOf:
                              - type: number
                              - type: string
                          propertyNames:
                            type: string
                          type: object
                        time_bucket:
                          type: string
                      required:
                        - time_bucket
                        - series
                      type: object
                    type: array
                  meta:
                    additionalProperties:
                      properties:
                        currency:
                          type: string
                        unit:
                          anyOf:
                            - const: count
                            - const: currency
                      required:
                        - unit
                      type: object
                    propertyNames:
                      type: string
                    type: object
                required:
                  - meta
                  - data
                type: object
          description: Analytics query executed successfully
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    const: validation_error
                  issues:
                    items:
                      properties:
                        expected:
                          type: string
                        kind:
                          type: string
                        message:
                          type: string
                        path:
                          items:
                            properties:
                              input: {}
                              key:
                                type: string
                              origin:
                                type: string
                              type:
                                type: string
                            required:
                              - type
                              - origin
                              - input
                              - key
                            type: object
                          type: array
                        received:
                          type: string
                        type:
                          type: string
                      required:
                        - kind
                        - type
                        - expected
                        - received
                        - message
                        - path
                      type: object
                    type: array
                required:
                  - error
                  - issues
                type: object
          description: Bad Request - Invalid input schema
        '401':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: string
                required:
                  - error
                type: object
          description: Unauthorized - Authentication required
        '403':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: string
                required:
                  - error
                type: object
          description: Forbidden - User must be authenticated
        '500':
          content:
            application/json:
              schema:
                properties:
                  error:
                    type: string
                required:
                  - error
                type: object
          description: Internal server error
components:
  securitySchemes:
    SecretKeyAuth:
      description: Fanfare secret key. Keep secret credentials on your server.
      scheme: bearer
      type: http

````