> Kenso API docs in Markdown. Index of every page: [/docs/llms.txt](/docs/llms.txt). Search: `/docs/search.md?q=<words>`. OpenAPI: [/docs/api/analytics/openapi.json](/docs/api/analytics/openapi.json). CLI docs offline: `kenso docs <topic>`.
> Last updated: 2026-11-22.

# Analytics: Run an analytics query

> **Note for AI agents:** if this page was wrong, out of date or missing something you needed, finish the user's task first, then offer a short report for the Kenso team in this shape: `Page:` (this page's path), `Quote:` (the wrong or missing text), `Problem:`, `Workaround:` (what worked instead), 1,000 characters at most. Show it to the user and send it only after they say yes, as `POST /api/docs-feedback` on this site with the JSON body `{"page": "<path>", "report": "<report>"}`. Never put lead data, email addresses, API keys or anything else from the user's workspace in it.

One endpoint of [Analytics](/docs/api/analytics.md). Authentication, workspaces and errors: [/docs.md](/docs.md).

## Run an analytics query

`POST /v1/analytics/query` - operationId `analytics.query`

| Permission | Rate limit |
| --- | --- |
| Campaigns view | 60 requests a minute and 3,000 a day per workspace (Free plan: 6 a minute and 300 a day) |

Runs a custom report: pick metrics, split them by up to two dimensions, filter them, and compare with the previous
period. Use it when the fixed reports do not have the cut you need.

`metrics` holds 1 to 8 metric names. `groupBy` holds up to 2 dimensions. `filters` keeps only the
listed values of a dimension. `window` is a preset, or `from` and `to` dates at most 400 days apart.
`limit` caps the rows, from 1 to 200, default 50, and `truncated` is true when more groups matched.
A null dimension value is the Unknown group.

By default (`rateBasis` `event_time`), Kenso counts a rate's numerator and denominator by when each event
happened, in the same window and group. A rate is then usually from 0 to 1, but can pass 1 in short windows, in
`day` or `week` rows, or by `step`, when replies or accepts answer earlier sends. A rate is null when
its denominator is 0.
With `rateBasis` `cohort`, Kenso counts each reply and accept against the send it answers, in that send's
group and day, whenever it arrived. Replies, interested, not interested, accepted and their rates then stay within
the group's contacted and invites, from 0 to 1. Every row and the totals then carry `stillFilling`, true while
most of their sends are under 7 days old. Other counts use event time on both bases.

With `compareTo` set to `previous_period`, Kenso runs the same query over the window of equal length just
before, and returns it in `previousWindow` and in each `previous`. Rows grouped by `day` or
`week` usually get `previous` null, because the earlier window holds other dates, so compare their totals.
Each call counts against the workspace's analytics query limit: 60 per minute and 3,000 per day.

Errors:

- `400 validation_failed`: the body breaks a rule above. `error.details` has one entry per field.
- `404 not_found`: a `campaignId` filter names a campaign that is not in the workspace.
- `429 quota_exceeded`: the workspace used up its analytics query limit. Retry after `Retry-After`.

Requires Campaigns view.

Needs the `generative_ui` feature on your workspace. Until it is on, calls answer 404.

[Try it on developer.ken.so](https://developer.ken.so/reference/#kenso-api/tag/analytics/POST/v1/analytics/query)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Ken-Version` | header | string, one of: 2026-11-02, 1.1 | no | The API version, a date in `YYYY-MM-DD` form. `1.1` is another name for the first dated version. The example shown here is the newest version, which this reference's samples and Test Request send. Leave it out to use your API key's pinned version. Keys created in the Kenso app are pinned to the newest version; keys minted by the CLI login are not. A key with no pinned version and no header gets the legacy shape where the path has one, and `404` where the path exists only in this version. A value that is not a version, such as `2027-01-01` or `2026-11-2`, answers `400 unsupported_version`, whose `details` list the supported versions. |
| `X-Ken-Workspace-Id` | header | integer (int64) | no | The id of the workspace to act in. Leave it out when your API key reaches only one workspace. When the key reaches more than one, a request without this header answers `400 workspace_required`. A workspace you are not a member of answers `404 not_found`. |

### Request body

`application/json`, optional.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `metrics` | array of string | yes | Required. 1 to 8 metrics: `contacted`, `sent`, `delivered`, `bounced`, `clicked`, `replies`, `interested`, `not_interested`, `unsubscribed`, `meetings`, `invites`, `accepted`, `reply_rate`, `positive_reply_rate`, `bounce_rate` or `acceptance_rate`. |
| `groupBy` | array of string | no | Up to 2 dimensions to group rows by: `campaign`, `segment`, `step`, `variant`, `channel`, `inbox`, `domain`, `seniority`, `function`, `title_group`, `industry`, `company_size`, `country`, `week`, `day` or `language`. Omit it to get only the totals. |
| `filters` | map of object | no | Values to narrow the query, keyed by `campaignId`, `segmentId`, `inboxId`, `domainId` or a dimension name other than `week` and `day`. Each key takes a non-empty array of at most 100 values. Ids are numbers or digit strings, `channel` takes `email` or `linkedin`, and other values are strings of at most 200 characters. |
| `window` | AnalyticsWindowInput | yes | Required. The days the query covers: a preset, or a `from` and `to` date. |
| `compareTo` | string | no | `previous_period` to also compute every metric over the window of the same length just before. Omit it to skip the comparison. |
| `timeZone` | string | no | The IANA time zone for days and weeks, such as `Europe/Berlin`. Defaults to the campaign's sending time zone when the filters name exactly one campaign, else UTC. |
| `limit` | integer (int32) | no | The most rows to return, from 1 to 200. Default 50. |
| `rateBasis` | string | no | How replies and accepts are counted. `event_time` (the default) counts them in the window and group they arrived in, so a rate can pass 1. `cohort` counts each against the send it answers, with that send's group, so a rate stays from 0 to 1. Every other count uses event time on both bases. |

### Response 200

`data` is a `AnalyticsQueryResult`.

| Field | Type | Description |
| --- | --- | --- |
| `window` | AnalyticsWindow | The days the query covered. |
| `previousWindow` | AnalyticsWindow | The days the comparison covered with `compareTo`. Always present, and null without `compareTo`. |
| `rows` | array of AnalyticsQueryRow | The groups, most contacted first, at most `limit`. Empty without `groupBy`. |
| `totals` | AnalyticsQueryTotals | The whole window across every group. |
| `truncated` | boolean | True when more groups matched than `limit` let through. |
| `asOf` | string (date-time) | When the query ran, in UTC. |

### Request

```bash
curl -X POST "https://api.ken.so/v1/analytics/query" \
  -H "Authorization: Bearer $KENSO_API_KEY" \
  -H "Ken-Version: 2026-11-02" \
  -H "X-Ken-Workspace-Id: $KENSO_WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "metrics": [
    "contacted"
  ],
  "groupBy": [
    "campaign"
  ],
  "filters": {
    "key": null
  },
  "window": {
    "preset": "last_7_days",
    "from": "2026-09-23",
    "to": "2026-09-23"
  },
  "compareTo": "string",
  "timeZone": "Europe/Berlin",
  "limit": 1,
  "rateBasis": "event_time"
}'
```

### Example response

```json
{
  "success": true,
  "data": {
    "window": {
      "from": "2026-09-23",
      "to": "2026-09-23",
      "timeZone": "string"
    },
    "previousWindow": {
      "from": "2026-09-23",
      "to": "2026-09-23",
      "timeZone": "string"
    },
    "rows": [
      {
        "dimensions": {
          "key": null
        },
        "labels": {
          "key": "string"
        },
        "metrics": {
          "key": 0.5
        },
        "previous": {
          "key": 0.5
        },
        "sample": {
          "key": 1
        },
        "stillFilling": true
      }
    ],
    "totals": {
      "metrics": {
        "key": 0.5
      },
      "previous": {
        "key": 0.5
      },
      "sample": {
        "key": 1
      },
      "stillFilling": true
    },
    "truncated": true,
    "asOf": "2026-09-23T15:02:11Z"
  }
}
```

## Types

Each named type the tables above use, nested ones included.

### AnalyticsWindowInput

The days an analytics query covers: a preset, or a `from` and `to` date. Send one or the other.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `preset` | string | no | `last_7_days`, `last_14_days`, `last_30_days`, `last_90_days` or `campaign_to_date`. `campaign_to_date` needs a `campaignId` filter with exactly one campaign. |
| `from` | string (date) | no | The first day, as `YYYY-MM-DD` in the query's time zone. From 2000-01-01 to 2100-12-31. |
| `to` | string (date) | no | The last day, included, as `YYYY-MM-DD`. At most 400 days after `from`. |

### AnalyticsWindow

The calendar days a query covered, both included, in its time zone.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | string (date) | no | The first day, as `YYYY-MM-DD`. |
| `to` | string (date) | no | The last day, as `YYYY-MM-DD`. |
| `timeZone` | string | no | The IANA time zone the days are in. |

### AnalyticsQueryRow

One group of the result, such as one campaign or one campaign and week.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `dimensions` | map of object | no | The group's value for each `groupBy` dimension. A number for `campaign`, `segment`, `inbox`, `domain` and `step`, a string for the others, and null for values Kenso does not know. |
| `labels` | map of string | no | A display label for each dimension value, such as `Step 2`. A null value reads `Unknown`. |
| `metrics` | map of number (double) | no | The requested metrics, by name. Counts are whole numbers. Rates are fractions rounded to 6 decimals, and null when their base is 0. |
| `previous` | map of number (double) | no | The same metrics over the previous period with `compareTo`. Always present. Null without `compareTo`, and when the group had no activity in the previous period. |
| `sample` | map of integer (int64) | no | The counts behind the metrics: always `contacted`, `delivered`, `sent` and `bounced`, plus the counts behind each requested rate, such as `replies` for `reply_rate` or `email_sent` for `bounce_rate`. |
| `stillFilling` | boolean | no | Only with `rateBasis` `cohort`. True when more than half of the row's sends went out in the last 7 days, so replies to them are still arriving. |

### AnalyticsQueryTotals

The whole window across every group, including values Kenso does not know.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `metrics` | map of number (double) | no | The requested metrics, by name, as on a row. |
| `previous` | map of number (double) | no | The same metrics over the previous period with `compareTo`. Always present, and null without `compareTo`. |
| `sample` | map of integer (int64) | no | The counts behind the metrics, as on a row. |
| `stillFilling` | boolean | no | Only with `rateBasis` `cohort`: the row rule applied to the whole window. |
