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

# Run a report query

> Runs a query you build from the fields of [list report query fields](/api-reference/cloudchat/endpoints/list-report-query-fields), over the ClaudIA projects you can access. The rows are split by every dimension you ask for, with each measure aggregated within the split, like a pivot table.

Reading data does not change anything, even though the call is a `POST`. The data is refreshed periodically, not in real time, and the same query within 10 minutes returns the cached answer. For the dashboard metrics, use [get a report](/api-reference/cloudchat/endpoints/get-a-report).



## OpenAPI

````yaml api-reference/specs/cloudchat/v1.json POST /v1/accounts/{accountId}/report-queries
openapi: 3.0.1
info:
  title: Cloud Chat API
  version: v1
  description: >-
    The curated public surface of Cloud Chat. Every call needs two things: the
    Bearer token from `POST /auth/v1/signin`, and the `cloudchat-instance`
    header that says which Cloud Chat instance your company lives on.


    If you don't know your instance value, the [Find your
    credentials](/api-reference/cloudchat/credentials) page reads it out of your
    own token in the browser.
servers:
  - url: https://api.cloudhumans.com/cloudchat
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Canned Responses
    description: >-
      Canned responses — the shortcuts agents expand while replying. Each one
      belongs to a single account and is identified by its short code.
  - name: Conversations
    description: >-
      Read-only access to the conversations of an account. What you can see
      follows the same rule as the dashboard: an administrator token sees every
      inbox, an agent token only the inboxes it is a member of.
  - name: Help Center
    description: >-
      Portals, categories and articles of the help center — the public FAQ your
      customers read.
  - name: Uploads
    description: Store the images help center articles embed.
  - name: Labels
    description: >-
      Read-only access to the labels an account has defined. A label is a tag
      conversations and contacts carry; this endpoint only lists the label
      definitions themselves.
  - name: Inboxes
    description: >-
      Read-only access to the inboxes a token can see — every inbox of the
      account for an administrator, only its memberships for an agent. Never
      includes the channel's credentials.
  - name: Agents
    description: >-
      Read-only access to the human and AI agents of an account. A hidden admin
      (the platform's own support user) never appears, on the list or by id.
  - name: Teams
    description: >-
      Teams group agents for assignment. Listing and reading are open to any
      member; creating and updating a team, and managing its membership, require
      an administrator token. A system-managed team (provisioned by the
      platform) can be read like any other but never updated.
  - name: Macros
    description: >-
      Macros bundle a sequence of actions an agent runs against a conversation
      from the dashboard. This surface lets you list, read and write macro
      definitions — running one is not part of the v1 contract. A macro is
      either `global` (visible to the whole account) or `personal` (visible only
      to its author); an agent token can only create personal macros.
  - name: Automation Rules
    description: >-
      Read-only access to the account's automation rules — administrator only.
      An agent token gets a 403 on every operation in this group.
  - name: Availability Reasons
    description: >-
      The reasons an agent can go `busy` for, configured per account. Listing is
      open to any member; creating, updating and deleting require an
      administrator token. Deleting is a soft delete — the reason disappears
      from listings but agents' past availability history keeps referencing it.
  - name: Native Attribute Requirements
    description: >-
      Which native conversation attributes (priority, assignee, tag, team) the
      account requires agents to fill before resolving a conversation. Listing
      is open to any member; requiring and un-requiring need an administrator
      token. Deleting a requirement is reversible — require the same key again
      to restore it.
  - name: Campaigns
    description: Check who a campaign would reach, send it, and read the result back.
  - name: Reports
    description: The numbers of the Cloud Chat reporting dashboards, read through the API.
paths:
  /v1/accounts/{accountId}/report-queries:
    parameters:
      - $ref: '#/components/parameters/CloudChatInstance'
      - $ref: '#/components/parameters/AccountId'
    post:
      tags:
        - Reports
      summary: Run a report query
      description: >-
        Runs a query you build from the fields of [list report query
        fields](/api-reference/cloudchat/endpoints/list-report-query-fields),
        over the ClaudIA projects you can access. The rows are split by every
        dimension you ask for, with each measure aggregated within the split,
        like a pivot table.


        Reading data does not change anything, even though the call is a `POST`.
        The data is refreshed periodically, not in real time, and the same query
        within 10 minutes returns the cached answer. For the dashboard metrics,
        use [get a report](/api-reference/cloudchat/endpoints/get-a-report).
      operationId: runReportQuery
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReportQueryRequest'
            example:
              query:
                fields:
                  - datamart_claudia__claudia_conversation.creation_date[week]
                  - datamart_claudia__claudia_conversation.taxa_retencao_pct
                from: '2026-09-21'
                to: '2026-10-11'
                sorts:
                  - field: datamart_claudia__claudia_conversation.creation_date[week]
      responses:
        '200':
          description: The rows of the query.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReportQueryResult'
              example:
                topic:
                  key: claudia_conversations
                  name: ClaudIA Conversations
                period:
                  from: '2026-09-21'
                  to: '2026-10-11'
                  axis: conversation_created
                fields:
                  - datamart_claudia__claudia_conversation.creation_date[week]
                  - datamart_claudia__claudia_conversation.taxa_retencao_pct
                filters: []
                projects:
                  - <YOUR_PROJECT>
                rows:
                  - datamart_claudia__claudia_conversation.creation_date[week]: '2026-09-21'
                    datamart_claudia__claudia_conversation.taxa_retencao_pct: 57.2
                  - datamart_claudia__claudia_conversation.creation_date[week]: '2026-09-28'
                    datamart_claudia__claudia_conversation.taxa_retencao_pct: 54.21
                  - datamart_claudia__claudia_conversation.creation_date[week]: '2026-10-05'
                    datamart_claudia__claudia_conversation.taxa_retencao_pct: 59.47
                truncated: false
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ReportQueriesForbidden'
        '404':
          $ref: '#/components/responses/ReportQueriesNotFound'
        '422':
          $ref: '#/components/responses/ReportQueriesValidationFailed'
        '429':
          $ref: '#/components/responses/ReportsTooManyRequests'
        '500':
          $ref: '#/components/responses/ReportsInternalError'
        '503':
          $ref: '#/components/responses/ReportQueriesUnavailable'
components:
  parameters:
    CloudChatInstance:
      name: cloudchat-instance
      in: header
      required: true
      description: >-
        Your Cloud Chat instance ID — an integer, fixed for your company, told
        at onboarding. [The API
        overview](/api-reference/cloudchat/overview#two-headers-every-call)
        explains how instances work, how to find yours, and the errors a wrong
        or missing value produces.
      schema:
        type: integer
        example: 1
    AccountId:
      name: accountId
      in: path
      required: true
      description: >-
        Your Cloud Chat account. It has to be an account your token grants
        membership on, and it has to live on the instance in the
        `cloudchat-instance` header — the two travel together. Account numbers
        are only unique **within** an instance, so the same number is a
        different company on another instance. Usually a mismatched pair fails
        closed with a 401, because your user does not exist on the other
        instance — but if your identity happens to exist on both, the call
        succeeds against the other company's data, silently. Read it and you are
        looking at the wrong help center; write it and you have stored into the
        wrong account. Send the two values that were given to you together, and
        never try a number to see what answers.
      schema:
        type: integer
        example: 1
  schemas:
    ReportQueryRequest:
      type: object
      description: A query and the topic it runs on.
      required:
        - query
      properties:
        topic:
          type: string
          description: >-
            The topic to query, as `key` in the fields list. Leave it out for
            `claudia_conversations`.
        query:
          type: object
          description: >-
            What to read: fields and period, and optionally filters, sorts and a
            row limit.
          required:
            - fields
            - from
            - to
          properties:
            fields:
              type: array
              description: >-
                Field names from the fields list, 1 to 20. Each one becomes a
                key of every row.
              items:
                type: string
            from:
              type: string
              description: >-
                First day of the period, `YYYY-MM-DD`, included. The date it
                filters on is the topic's `date_axis`.
            to:
              type: string
              description: >-
                Last day of the period, `YYYY-MM-DD`, included. At most
                `max_days` after `from`.
            filters:
              type: array
              description: >-
                Conditions every row must meet, at most one per field. To
                restrict the query to some of your ClaudIA projects, filter the
                project field; without it the query covers all of them.
              items:
                type: object
                description: One filter condition.
                required:
                  - field
                  - operator
                  - values
                properties:
                  field:
                    type: string
                    description: A `STRING` dimension from the fields list.
                  operator:
                    type: string
                    enum:
                      - equals
                      - not_equals
                    description: >-
                      `equals` keeps the rows whose value is one of `values`;
                      `not_equals` drops them.
                  values:
                    type: array
                    description: >-
                      1 to 50 exact values, up to 200 characters each. A value
                      that matches nothing returns no rows, not an error. On the
                      project field, a project you cannot access answers `422`
                      listing the ones you can use.
                    items:
                      type: string
            sorts:
              type: array
              description: >-
                The row order, first entry first. Only fields the query asks
                for.
              items:
                type: object
                required:
                  - field
                properties:
                  field:
                    type: string
                    description: A field the query asks for.
                  descending:
                    type: boolean
                    description: '`true` for highest or latest first. Defaults to `false`.'
            limit:
              type: integer
              description: The most rows to return, 1 to 1000. Defaults to 100.
    ReportQueryResult:
      type: object
      description: The rows of one query.
      required:
        - topic
        - period
        - fields
        - filters
        - projects
        - rows
        - truncated
      properties:
        topic:
          type: object
          description: The topic the query ran on.
          required:
            - key
            - name
          properties:
            key:
              type: string
              description: The topic key.
            name:
              type: string
              description: The topic name.
        period:
          type: object
          description: The period the rows cover.
          required:
            - from
            - to
            - axis
          properties:
            from:
              type: string
              description: First day, `YYYY-MM-DD`.
            to:
              type: string
              description: Last day, `YYYY-MM-DD`, included.
            axis:
              type: string
              description: Which date the period filters on.
        fields:
          type: array
          description: The fields asked for, in the order sent.
          items:
            type: string
        filters:
          type: array
          description: >-
            The filters applied, except the project filter, which `projects`
            reflects.
          items:
            type: object
            description: One filter condition.
            required:
              - field
              - operator
              - values
            properties:
              field:
                type: string
                description: A `STRING` dimension from the fields list.
              operator:
                type: string
                enum:
                  - equals
                  - not_equals
                description: >-
                  `equals` keeps the rows whose value is one of `values`;
                  `not_equals` drops them.
              values:
                type: array
                description: >-
                  1 to 50 exact values, up to 200 characters each. A value that
                  matches nothing returns no rows, not an error. On the project
                  field, a project you cannot access answers `422` listing the
                  ones you can use.
                items:
                  type: string
        projects:
          type: array
          description: The ClaudIA projects the query covered.
          items:
            type: string
        rows:
          type: array
          description: >-
            The rows, keyed by field name. `NUMBER` values are numbers,
            `BOOLEAN` values are booleans, other values are text (a week reads
            `2026-09-21`), and a missing value is `null`.
          items:
            type: object
            additionalProperties: true
        truncated:
          type: boolean
          description: >-
            `true` when more rows exist than `limit`, or the rows hit the
            response size cap. Narrow the period or the filters, or raise
            `limit`.
        warnings:
          type: array
          description: >-
            Present only when something limited the answer, and then `rows` is
            empty. `no_claudia_projects`: you can access no ClaudIA project on
            this account. `no_matching_projects`: the project filter left none
            of yours.
          items:
            type: string
    Error:
      type: object
      description: The error envelope every Cloud Chat API response uses.
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: >-
                The stable, machine-readable reason. Branch on this, never on
                `message`.
              enum:
                - unauthorized
                - forbidden
                - not_found
                - validation_failed
                - bad_request
                - internal_error
                - rate_limited
                - service_unavailable
              example: not_found
            message:
              type: string
              description: >-
                The reason in words, localized to your account's language
                (English, Spanish or Brazilian Portuguese; English when the
                account is set to anything else). Wording changes with the
                account and between releases, so never match on it.


                Two cases stay in English whatever the account is set to:
                `unauthorized`, decided before any account is known, and the
                account-level `not_found`, which must not reveal the account's
                language.
              example: Resource could not be found.
            details:
              type: array
              description: >-
                Present on some rejections — a 400 for a refused query parameter
                or upload mode, for example. One entry per offending field,
                localized to the account's language like `message` — match on
                `code` and `field`, never on the text.
              items:
                type: object
                required:
                  - field
                  - code
                  - message
                properties:
                  field:
                    type: string
                    description: Which request field the rule was about.
                  code:
                    type: string
                    description: Stable, machine-readable reason.
                  message:
                    type: string
                    description: The rule in words.
    ValidationError:
      type: object
      description: A `validation_failed` error, which carries `details`.
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - details
          properties:
            code:
              type: string
              enum:
                - validation_failed
              example: validation_failed
            message:
              type: string
              description: >-
                Localized to the account's language, like every other envelope
                message.
              example: The request payload is invalid.
            details:
              type: array
              description: >-
                One entry per rejected field. Unlike the envelope message above,
                the texts come from the model layer and are in English in
                practice (the model layer ships no translations) — match on code
                and field, never on the text.
              items:
                type: object
                required:
                  - field
                  - code
                  - message
                properties:
                  field:
                    type: string
                    description: >-
                      Which request field the rule was about — `short_code` or
                      `content`. A rule that is not tied to either is reported
                      as `base`, so treat `base` as "the payload as a whole"
                      rather than a field you can highlight.
                    enum:
                      - short_code
                      - content
                      - base
                    example: short_code
                  code:
                    type: string
                    description: >-
                      Which rule it broke — `blank` for a missing or empty
                      value, `taken` for a `short_code` already used on the
                      account.
                    example: taken
                  message:
                    type: string
                    example: has already been taken
    GatewayError:
      type: object
      description: >-
        Rejected by the gateway before Cloud Chat saw it, so it does not use the
        `error` envelope.
      required:
        - message
      properties:
        message:
          type: string
          example: API rate limit exceeded
        request_id:
          type: string
          description: Gateway request id. Quote it when reporting a problem.
          example: f3f7567638d4b65a8003057d0c77d275
  responses:
    BadRequest:
      description: >-
        The request itself is malformed, before any value is validated:


        - a body that isn't valid JSON, or one with no `canned_response`
        wrapper,

        - a `canned_response` that isn't an object (`{"canned_response":
        "text"}`),

        - `page`, `per_page`, `search` or `sort` sent as an array or a nested
        object (`?page[]=1`, `?sort[x]=y`) instead of a plain value,

        - **the `cloudchat-instance` header missing or holding a value we don't
        route,**

        - an `accountId` that is not a number — including the literal
        `{accountId}` that some API clients send when the argument is left
        unset. This one answers with the normal envelope and `error.details`
        naming `accountId`, and it is deliberately **not** a 404: a 404 would
        mean the account cannot be reached, while this means the value was never
        an account id at all, so re-read the argument instead of trying other
        numbers.


        **Two different shapes answer with 400, and the difference will bite you
        on day one.** That last case is rejected before the request reaches the
        API, so `error` is a plain **string** instead of the usual object:


        ```json

        { "error": "<human-readable message>" }

        ```


        Every other 400 uses the normal envelope, where `error` is an object
        with `code` and `message`. Reading `error.code` without checking the
        type first throws on the missing-header case — which is the most likely
        400 of your first integration. Check `typeof error === "string"` first,
        or read `error?.code` defensively.


        A 400 always means fix the request shape; it never means a value was
        rejected. Rejected values are 422.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: bad_request
              message: The request is malformed.
    Unauthorized:
      description: >-
        No Bearer token, or one that is expired, malformed, or not a Cognito
        token. Sign in again for a fresh `id_token`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: >-
                Authentication is required. Send a valid Bearer token in the
                Authorization header.
    ReportQueriesForbidden:
      description: >-
        Running queries needs an administrator, supervisor or CX engineer role.
        A suspended account also answers `403`, and then nothing on it works
        until it is reactivated.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: forbidden
              message: You are not allowed to perform this action.
    ReportQueriesNotFound:
      description: >-
        The account does not exist, you are not a member of it, queries are not
        enabled on it, or the `topic` does not exist. These cases are
        deliberately indistinguishable.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: Resource could not be found.
    ReportQueriesValidationFailed:
      description: >-
        A query that cannot run as asked. `error.details` names each part at
        fault and what it accepts: an unknown field, too many fields, a filter
        on a field that is not a `STRING` dimension, a field filtered twice, a
        sort on a field the query does not ask for, a `limit` out of range, a
        malformed, reversed or too long period, a project you cannot access, or
        a combination of fields the reporting backend refuses.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
          example:
            error:
              code: validation_failed
              message: The request payload is invalid.
              details:
                - field: fields
                  code: inclusion
                  message: >-
                    Unknown fields: <FIELD>. List the available ones with the
                    query fields endpoint
    ReportsTooManyRequests:
      description: >-
        Rate limited. The gateway answers `{ "message": ... }`, with
        `Retry-After` and the `ratelimit-*` headers carrying the current values.
        Other limits answer the usual envelope with code `rate_limited` and can
        apply even when your account made few calls: wait a minute before
        retrying. Don't hardcode any limit.
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/GatewayError'
              - $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Too many requests. Wait a minute and try again.
    ReportsInternalError:
      description: >-
        Something broke on our side. It is reported to our monitoring
        automatically. Retrying the same call will not help until it is fixed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: internal_error
              message: An unexpected error occurred. Please try again later.
    ReportQueriesUnavailable:
      description: >-
        The reporting backend is unavailable or did not answer in time. Retry in
        a few minutes; if it persists, ask for a shorter period or fewer fields.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: service_unavailable
              message: >-
                The reporting service is temporarily unavailable. Try again in a
                few minutes.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        The `id_token` from `POST /auth/v1/signin`, sent as `Authorization:
        Bearer <id_token>`. Not the `access_token` — that one does not carry the
        identity Cloud Chat authorizes on.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.