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

# v2 Stats Query

> For any query (JSON object) with question, audiences and filters in request body it responses with results for chart builder metrics according the query.



## OpenAPI

````yaml post /v2/query/stats
openapi: 3.0.0
info:
  title: Stats Query
  description: Query for Chart Builder.
  version: 2.0.0
servers:
  - url: https://api.globalwebindex.com
security: []
paths:
  /v2/query/stats:
    post:
      tags:
        - Query
      summary: v2 Stats Query
      description: >-
        For any query (JSON object) with question, audiences and filters in
        request body it responses with results for chart builder metrics
        according the query.
      operationId: StatsQuery
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StatsQuery'
        description: Chart builder query.
        required: true
      responses:
        '200':
          description: Correct results for given query.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatsQueryResults'
        '400':
          description: Invalid query in request body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
        '401':
          description: Auth bearer doesn't have permissions to access this endpoint.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
        '403':
          description: >-
            Auth bearer doesn't have permissions to access some codes in
            requested query.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenError'
        '500':
          description: Server is not able to give correct response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    StatsQuery:
      type: object
      description: Question, audiences and filters as parameters for chart builder metrics.
      title: Query
      required:
        - question
      properties:
        question:
          type: string
          description: Question code to define datapoint scope.
          example: q20
        datapoints:
          type: array
          description: Datapoint codes to limit scopes of interest.
          items:
            type: string
          example:
            - q20_3
            - q20_1
            - q20_5
            - q20_6
            - q20_7
            - q20_4
            - q20_2
        suffixes:
          type: array
          description: Suffixes to extend datapoint codes for more detailed responses.
          items:
            type: string
          example:
            - '1'
            - '2'
            - '3'
        splitter:
          type: string
          description: Either 'waves' or question code used to split results to segments.
          example: waves
        segments:
          type: array
          description: >-
            List of wave codes, location codes or datapoint codes used to limit
            which segments scopes are created.
          items:
            type: string
          example:
            - q1_2019
            - q2_2019
            - q3_2019
            - q4_2019
        segmented_base:
          type: boolean
          description: Switch to use each segment as base scope when doing segmentation.
        audiences:
          type: array
          description: List of audiences to scope question responses.
          items:
            $ref: '#/components/schemas/Audience'
        locations:
          type: array
          description: List of location codes to filter.
          items:
            type: string
          example:
            - s2_1
            - s2_44
        waves:
          type: array
          description: List of wave codes to filter.
          items:
            type: string
          example:
            - q1_2019
            - q2_2019
            - q3_2019
            - q4_2019
        base_audience:
          $ref: '#/components/schemas/BaseAudience'
    StatsQueryResults:
      type: object
      description: Result of chart builder query
      title: QueryResults
      required:
        - meta
        - data
      properties:
        meta:
          $ref: '#/components/schemas/StatsQueryResultMetadata'
        data:
          type: array
          description: Collection of results of chart builder query
          items:
            $ref: '#/components/schemas/StatsQueryResultsData'
    BadRequestError:
      type: object
      description: Something is wrong with request content.
      title: Error
      required:
        - error
        - error_type
        - code
      properties:
        error:
          type: string
          description: Description.
          example: some_error
        error_type:
          type: string
          example: empty_expression
          description: Machine readable representation of error.
        code:
          type: integer
          description: Numeric representation of error.
          example: 400
        message:
          type: string
          description: Human readable error message
          example: Message readable by customer.
    ForbiddenError:
      type: object
      description: Some content is not permitted.
      title: Error
      required:
        - error
        - error_type
        - code
      properties:
        error:
          type: string
          description: Description.
          example: some_error
        error_type:
          type: string
          example: empty_expression
          description: Machine readable representation of error.
        code:
          type: integer
          description: Numeric representation of error.
          example: 403
        meta:
          $ref: '#/components/schemas/ForbiddenErrorMeta'
    Audience:
      type: object
      description: Wrapper structure containing AudienceExpression.
      title: Audience
      properties:
        id:
          type: string
          example: '133'
        name:
          type: string
          example: my_audience
        expression:
          $ref: '#/components/schemas/AudienceExpression'
    BaseAudience:
      type: object
      description: Wrapper structure containing AudienceExpression.
      title: BaseAudience
      properties:
        id:
          type: string
          example: '123'
        name:
          type: string
          example: base_audience
        expression:
          $ref: '#/components/schemas/AudienceExpression'
    StatsQueryResultMetadata:
      type: object
      description: Metadata for chart builder query result
      title: StatsQueryResultMetadata
      required:
        - type
        - question
      properties:
        type:
          type: string
          description: Query type identifier.
          enum:
            - DATAPOINTS
            - DATAPOINTS-SEGMENTS
            - DATAPOINTS-AUDIENCES
            - DATAPOINTS-SEGMENTS-AUDIENCES
          example: DATAPOINTS-SEGMENTS
        question:
          type: string
          description: Question code taken from requested query.
          example: q20
        splitter:
          type: string
          description: Splitter code taken from request query.
          example: waves
    StatsQueryResultsData:
      type: object
      description: Result of chart builder query
      title: QueryResultsData
      required:
        - datapoint
        - waves
        - metrics
      properties:
        datapoint:
          type: string
          description: Datapoint code taken from requested query.
          example: q20_3
        waves:
          type: array
          description: Codes of all waves which are positive for responses.
          items:
            type: string
          example:
            - q1_2019
            - q2_2019
            - q3_2019
            - q4_2019
        segment:
          type: string
          description: Segment code used to scope results.
          example: q1_2019
        metrics:
          $ref: '#/components/schemas/StatsQueryResultMetrics'
        audience:
          type: string
          description: Audience ID taken from requested query.
          example: '133'
        suffixes:
          type: array
          description: Suffixes to extend datapoint codes for more detailed responses.
          items:
            type: number
          example:
            - 1
            - 2
            - 3
    ForbiddenErrorMeta:
      type: object
      description: Additional metadata to aid message/error strings
      properties:
        forbidden_codes:
          type: object
          properties:
            questions:
              type: array
              items:
                $ref: '#/components/schemas/PermissionsQuestion'
            locations:
              type: array
              items:
                type: string
              example:
                - s2_44
            waves:
              type: array
              items:
                type: string
              example:
                - q1_2019
    AudienceExpression:
      type: object
      description: Flexible expression of audience scope.
      title: AudienceExpression
      properties:
        and:
          type: array
          description: List of sub-expressions to apply intersection of their scopes.
          items:
            $ref: '#/components/schemas/AudienceExpression'
        or:
          type: array
          description: List of sub-expressions to apply union of their scopes.
          items:
            $ref: '#/components/schemas/AudienceExpression'
        not:
          type: boolean
          description: To use negation of the expression.
        question:
          type: string
          description: Question code to define datapoint scope.
          example: q2
        datapoints:
          type: array
          description: Datapoint codes to limit scopes of interest.
          items:
            type: string
          example:
            - q2_1
            - q2_2
        suffixes:
          type: array
          description: Suffixes to extend datapoint codes for more detailed responses.
          items:
            type: string
          example:
            - '1'
            - '2'
            - '3'
        min_count:
          type: integer
          description: Minimal count of positive datapoints in one response.
          example: 1
      example:
        and:
          - question: q2
            datapoints:
              - q2_1
              - q2_2
            min_count: 1
            not: false
          - question: q20
            datapoints:
              - q20_2
            min_count: 1
            suffixes:
              - '1'
              - '2'
              - '3'
            not: false
    StatsQueryResultMetrics:
      type: object
      description: Chart builder metrics returned for requested question.
      title: QueryResultMetrics
      required:
        - positive_size
        - positive_sample
        - audience_index
        - audience_percentage
        - audience_sample
        - audience_size
        - datapoint_percentage
        - datapoint_sample
        - datapoint_size
      properties:
        positive_size:
          type: integer
          description: >-
            Final weighted universe in intersection of audience and datapoint
            scopes.
        positive_sample:
          type: integer
          description: >-
            Final count of responses in intersection of audience and datapoint
            scopes.
        audience_index:
          type: number
          description: Likeliness ratio between audience and datapoint scopes.
        audience_percentage:
          type: number
          description: Ratio between audience with and without datapoint scope.
        audience_sample:
          type: integer
          description: Count of responses in audience without datapoint scope.
        audience_size:
          type: integer
          description: Weighted universe of audience without datapoint scope.
        datapoint_percentage:
          type: number
          description: Ratio between datapoint with and without audience scope.
        datapoint_sample:
          type: integer
          description: Count of responses in datapoint without audience scope.
        datapoint_size:
          type: integer
          description: Weighted universe of datapoint without audience scope.
    PermissionsQuestion:
      type: object
      properties:
        code:
          type: string
          example: q2
        datapoints:
          type: array
          items:
            type: string
          example:
            - q1_1
        origin:
          type: string
          example: question
          enum:
            - question
            - audience
            - splitter
  securitySchemes:
    ApiKeyAuth:
      in: header
      name: Authorization
      type: apiKey

````