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

# Query phishing analytics

> Computes phishing figures across campaigns: the `metrics` asked for, in one row for each combination of the `groupBy` fields' values, or a single row without `groupBy`. A row's fields are named after the metrics and `groupBy` fields asked for. `failure_rate` and `pass_rate` are percentages of the people sent a simulation; the `distinct_` metrics count people, campaigns or templates; every other metric counts events. `startDate` and `endDate` go by the day of each event. Rows come in `groupBy` order unless `sortBy` names a metric or field to order them by. Grouping by `employee_name` or `email`, or filtering by `userIds`, also needs the scope `phishing_analytics:view_employee_data`, and is refused with `403` without it. Pages with `limit` and `offset`: the answer has `totalCount` for the whole list and, while more remain, `nextOffset` to pass back as `offset`. The whole result is computed for the first page and kept for about a minute for the pages after it, so read a result through without long pauses.



## OpenAPI

````yaml https://api.cimento.app/v1/openapi.json get /v1/phishing/analytics
openapi: 3.1.0
info:
  description: >-
    Read-only access to a Cimento tenant's phishing, training and AutoPhish
    data, for a customer's own systems.


    **Authentication.** Every route takes an OAuth 2.0 access token for an API
    service account, as `Authorization: Bearer <token>`. Create the account in
    Cimento under Integrations, API access, then exchange its client ID and
    secret for a token at the token URL with the client credentials grant. A
    token lasts an hour and carries the scopes the account was given; each route
    says which it needs.


    **Requests.** Every route is a `GET`. A parameter that takes a list takes
    its values separated by commas. A parameter the route does not have, or one
    given twice, is refused.


    **Paging.** Paging differs by route and each says which it uses. Most lists
    take `limit` and `offset` and answer with `totalCount` and, while more
    remain, `nextOffset`. Two AutoPhish lists take a `cursor` and answer with
    `nextCursor`, with no total.


    **Rate limit.** Each service account may make a short burst of requests and
    then about one a second. Past that the answer is `429` with a `Retry-After`
    header, in seconds.


    **Errors.** Every error has one shape,
    `{"error":{"code":"...","message":"..."}}`.
  title: Cimento Analytics API
  version: '1'
servers:
  - url: https://api.cimento.app
security: []
tags:
  - description: >-
      AutoPhish, the tenant's one continuous phishing program: its settings, its
      results and what people did with its simulations.
    name: autophish
  - description: >-
      Phishing campaigns: the figures across them, and the campaigns and
      templates those figures can be filtered by.
    name: phishing
  - description: Training campaigns and the courses they assign.
    name: training
paths:
  /v1/phishing/analytics:
    get:
      tags:
        - phishing
      summary: Query phishing analytics
      description: >-
        Computes phishing figures across campaigns: the `metrics` asked for, in
        one row for each combination of the `groupBy` fields' values, or a
        single row without `groupBy`. A row's fields are named after the metrics
        and `groupBy` fields asked for. `failure_rate` and `pass_rate` are
        percentages of the people sent a simulation; the `distinct_` metrics
        count people, campaigns or templates; every other metric counts events.
        `startDate` and `endDate` go by the day of each event. Rows come in
        `groupBy` order unless `sortBy` names a metric or field to order them
        by. Grouping by `employee_name` or `email`, or filtering by `userIds`,
        also needs the scope `phishing_analytics:view_employee_data`, and is
        refused with `403` without it. Pages with `limit` and `offset`: the
        answer has `totalCount` for the whole list and, while more remain,
        `nextOffset` to pass back as `offset`. The whole result is computed for
        the first page and kept for about a minute for the pages after it, so
        read a result through without long pauses.
      operationId: queryPhishingAnalytics
      parameters:
        - description: What to compute, at least one
          explode: false
          in: query
          name: metrics
          required: true
          schema:
            items:
              enum:
                - failure_rate
                - pass_rate
                - distinct_users_sent
                - distinct_users_failed
                - distinct_users_passed
                - distinct_campaigns
                - distinct_templates
                - sent
                - delivered
                - bounced
                - opened_email
                - clicked_link
                - opened_attachment
                - downloaded_file
                - visited_fake_page
                - visited_awareness_page
                - entered_credentials
                - submitted_form
                - replied_to_email
                - replied
                - answered_call
                - read_sms
                - scanned_qr
                - viewed_message
                - called_phone_number
                - complied_with_request
                - provided_sensitive_info
                - reported_email
                - completed_successfully
                - completed_remediation_training
              type: string
            type: array
          style: form
        - description: >-
            Give each combination of these fields' values a row of its own.
            Without any, one row covers everything
          explode: false
          in: query
          name: groupBy
          required: false
          schema:
            items:
              enum:
                - event_date
                - event_month
                - event_quarter
                - event_year
                - campaign
                - phishing_channel
                - template
                - difficulty
                - event_type
                - simulation_status
                - organization
                - division
                - department
                - cost_center
                - country
                - state_province
                - city
                - employee_name
                - email
                - job_title
                - user_type
                - manager
                - manager_email
              type: string
            type: array
          style: form
        - description: Only events on or after this day
          in: query
          name: startDate
          required: false
          schema:
            format: date
            pattern: ^\d{4}-\d{2}-\d{2}$
            type: string
        - description: Only events on or before this day
          in: query
          name: endDate
          required: false
          schema:
            format: date
            pattern: ^\d{4}-\d{2}-\d{2}$
            type: string
        - description: Only these phishing campaigns
          explode: false
          in: query
          name: campaignIds
          required: false
          schema:
            items:
              format: uuid
              pattern: >-
                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
              type: string
            type: array
          style: form
        - description: Only these phishing templates
          explode: false
          in: query
          name: templateIds
          required: false
          schema:
            items:
              format: uuid
              pattern: >-
                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
              type: string
            type: array
          style: form
        - description: Only these people
          explode: false
          in: query
          name: userIds
          required: false
          schema:
            items:
              format: uuid
              pattern: >-
                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
              type: string
            type: array
          style: form
        - description: Only these channels
          explode: false
          in: query
          name: phishingChannels
          required: false
          schema:
            items:
              enum:
                - email
                - sms
                - phone_call
                - multi_channel
                - qr_code
                - instant_messaging
                - social_media
              type: string
            type: array
          style: form
        - description: Order the rows by one of the metrics or groupBy fields asked for
          in: query
          name: sortBy
          required: false
          schema:
            type: string
        - description: With sortBy, desc unless asc is given
          in: query
          name: sortOrder
          required: false
          schema:
            enum:
              - asc
              - desc
            type: string
        - description: How many to return, up to 100. Defaults to 20
          in: query
          name: limit
          required: false
          schema:
            default: 20
            maximum: 100
            minimum: 1
            type: integer
        - description: 'How many to skip: the nextOffset of the previous page'
          in: query
          name: offset
          required: false
          schema:
            minimum: 0
            type: integer
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryPhishingAnalyticsResult'
          description: What was asked for.
        '400':
          $ref: '#/components/responses/InvalidRequest'
        '401':
          $ref: '#/components/responses/InvalidToken'
        '403':
          $ref: '#/components/responses/InsufficientScope'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '503':
          $ref: '#/components/responses/Unavailable'
      security:
        - oauth2:
            - phishing_analytics:view
components:
  schemas:
    QueryPhishingAnalyticsResult:
      additionalProperties: false
      properties:
        nextOffset:
          description: The offset of the next page. Absent on the last
          type:
            - 'null'
            - integer
        rows:
          description: One per group, holding its groupBy fields' values and its metrics
          items:
            additionalProperties: true
            type: object
          type:
            - 'null'
            - array
        totalCount:
          description: How many rows there are, across every page
          type: integer
      required:
        - rows
        - totalCount
      type: object
    Error:
      additionalProperties: false
      description: What every error answers with.
      properties:
        error:
          additionalProperties: false
          properties:
            code:
              description: >-
                Which error it is, one of `invalid_request`, `invalid_token`,
                `insufficient_scope`, `not_found`, `rate_limited`,
                `unavailable`. Stable: branch on this, and treat one you do not
                know as the status alone.
              type: string
            message:
              description: >-
                What went wrong, for a developer to read. The wording can
                change.
              type: string
          required:
            - code
            - message
          type: object
      required:
        - error
      type: object
  responses:
    InvalidRequest:
      content:
        application/json:
          example:
            error:
              code: invalid_request
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: >-
        A parameter is unknown, repeated, empty or not what the route takes. The
        message names it and says what is wrong.
    InvalidToken:
      content:
        application/json:
          example:
            error:
              code: invalid_token
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: >-
        No access token was sent, or it is expired or not valid. Get another
        from the token URL.
      headers:
        WWW-Authenticate:
          description: Always `Bearer error="invalid_token"`.
          schema:
            type: string
    InsufficientScope:
      content:
        application/json:
          example:
            error:
              code: insufficient_scope
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: >-
        The token lacks a scope the route needs, which the message then names,
        or the account may not read what was asked for.
    NotFound:
      content:
        application/json:
          example:
            error:
              code: not_found
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: >-
        Nothing has that ID, or the tenant does not have the feature the route
        belongs to.
    RateLimited:
      content:
        application/json:
          example:
            error:
              code: rate_limited
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: >-
        The service account is making requests too quickly. Wait the seconds
        `Retry-After` gives, then try again.
      headers:
        Retry-After:
          description: How many seconds to wait before the next request.
          schema:
            type: integer
    Unavailable:
      content:
        application/json:
          example:
            error:
              code: unavailable
              message: ...
          schema:
            $ref: '#/components/schemas/Error'
      description: The service could not answer just now. Try again shortly.
  securitySchemes:
    oauth2:
      description: >-
        An API service account's access token, from the client credentials
        grant.
      flows:
        clientCredentials:
          scopes:
            phishing:admin: AutoPhish activity and settings
            phishing_analytics:view: Phishing analytics
            phishing_analytics:view_employee_data: Phishing results for named employees
            phishing_campaigns:view: Phishing campaigns
            phishing_templates:view: Phishing templates
            training_campaigns:view: Training campaigns
            training_courses:view: Training courses
          tokenUrl: https://api.cimento.app/oauth2/token
      type: oauth2

````

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