Statistics: reports and export
The Statistics API returns aggregated tracker reports — metrics × groupings × filters for a period. This is the same data shown by the Report builder in the cabinet. Suitable for BI systems, regular exports and external dashboards.
Keys of metrics, groupings and filterable fields are listed in the article Statistics: field reference. Getting a token and the general response and error format are described in the section's main article.
Scopes
| Scope | Access | In default PAT |
|---|---|---|
api:stats |
POST /api/stats/query — reports |
yes |
api:stats:export |
POST /api/stats/export/csv — CSV export |
yes |
api:stats:meta |
GET /api/stats/meta/* — reference data |
yes |
All operations require the statistics query permission — all roles have it. BUYER sees only their own statistics, TEAM_LEAD sees team statistics subject to resource access settings, TEAM_OWNER and TECH see the team, ADMIN sees everything.
Endpoints
Base prefix — /api/stats. Request bodies are JSON, responses are application/json (text/csv for export).
| Method | Path | Scope | Purpose |
|---|---|---|---|
POST |
/api/stats/query |
api:stats |
Report: metrics × groupings + filters, with pagination |
POST |
/api/stats/export/csv |
api:stats:export |
The same selection as CSV (no pagination, up to 100,000 rows) |
GET |
/api/stats/meta/metrics |
api:stats:meta |
Metrics catalog |
GET |
/api/stats/meta/groups |
api:stats:meta |
Groupings catalog |
GET |
/api/stats/meta/filters |
api:stats:meta |
List of filterable fields |
GET |
/api/stats/meta/distinct?field=&q=&limit= |
api:stats:meta |
Field value suggestions (autocomplete) |
GET |
/api/stats/meta/os-versions?q=&limit= |
api:stats:meta |
OS version suggestions |
/api/stats/**has a separate rate limit — 3 requests per second per IP (burst 10). Above the limit, the gateway responds with429.
POST /api/stats/query
Request body (StatsQueryDto):
{
"time": {
"preset": "last7", // OR from/to
"from": "2026-05-01 00:00:00",
"to": "2026-05-20 23:59:59",
"timezone": "UTC"
},
"groups": ["day", "cmp_campaign"],
"metrics": ["clicks", "cpa_accept", "revenue", "roi"],
"filters": [
{ "field": "user_country", "op": "in", "value": ["US", "CA"] },
{ "field": "cmp_offer", "op": "eq", "value": "65f0…" }
],
"pagination": { "page": 1, "limit": 100 },
"sort": { "field": "clicks", "order": "desc" },
"attributionWindow": { "hours": 24, "eventType": "click" }
}
Request fields
| Field | Type | Req. | Description |
|---|---|---|---|
time |
TimeRangeDto |
yes | Report time range |
groups |
string[] |
no | Grouping keys (see the reference). An empty array returns the “total” aggregate |
metrics |
string[] |
no | Metric keys (see the reference). Default: ["clicks"] |
filters |
FieldFilterDto[] |
no | Field filters (see below) |
pagination |
{ page, limit } |
no | page ≥ 1, 1 ≤ limit ≤ 100000 (default 100) |
sort |
{ field, order } |
no | order ∈ {asc, desc}; field — a metric or grouping key from the request |
attributionWindow |
{ hours, eventType } |
no | Attribution window for Push metrics: 1 ≤ hours ≤ 720, eventType ∈ {click, view} |
time (TimeRangeDto)
| Field | Description |
|---|---|
preset |
one of the presets below; takes precedence over from/to |
from |
'YYYY-MM-DD' or 'YYYY-MM-DD HH:mm:ss' (separator — a space or T). No milliseconds and no time zone suffix (Z, +03:00) — such a format returns a validation error |
to |
same; optional if from is set |
timezone |
IANA time zone (Europe/Moscow), default UTC. Range boundaries and time groupings are calculated in it |
Pass either preset or from (optionally with to).
| Preset | Period |
|---|---|
today |
today from 00:00 to the current moment |
yesterday |
the full previous day |
last7 |
the last 7 days, including today |
last30 |
the last 30 days |
thisWeek |
from Monday of the current week |
prevWeek |
the previous full week (Mon–Sun) |
thisMonth |
from the 1st of the current month |
prevMonth |
the previous full month |
filters[] (FieldFilterDto)
Each filter is { "field", "op", "value" }. The field must be in the GET /api/stats/meta/filters list.
Operator op |
Semantics | Type of value |
|---|---|---|
eq |
equals | string/number |
neq |
not equal | string/number |
in |
value is in the list | array |
not_in |
value is not in the list | array |
gt / gte |
greater than / greater than or equal | number |
lt / lte |
less than / less than or equal | number |
between |
within range | [min, max] — a 2-element array |
like |
case-insensitive substring (ClickHouse ILIKE) |
string with % |
Server-side filters. The cmp_team and cmp_user fields are always overridden by the server according to the token owner's role: a client-supplied cmp_team value is ignored, and cmp_user is intersected with the allowed set of users. You cannot scope a report to someone else's data via the API.
Rules
groupsandmetricsaccept only keys from the reference catalogs; an unknown key results in a422error.- If a grouping has a “name” variant (
cmp_campaign↔cmp_campaign_name), it is added to the rows automatically — no need to pass it separately. attributionWindowaffects only Push Attribution metrics (push_postclick_*); without it these metrics return zeros.- LTV/Cohort metrics (
ltv_*,ftds,registrations…) are used together with thecohort_*,reg_cohort_*,lifetime_days*groupings. - For
query,limit ≤ 10 000is recommended; use CSV for a full export.
Response example
{
"data": {
"rows": [
{
"day": "2026-05-13T00:00:00+00:00",
"cmp_campaign": "65f0…",
"cmp_campaign_name": "Brand A — RU",
"clicks": 18432,
"cpa_accept": 122,
"revenue": 2840.55,
"roi": 0.36
}
],
"total": { "clicks": 18432, "cpa_accept": 122, "revenue": 2840.55 },
"page": 1,
"limit": 100,
"rowCount": 1
},
"traceId": "01HX…"
}
rows — report rows (grouping keys + metrics), total — the total for the whole selection regardless of pagination, rowCount — the number of rows on the current page. Ratios (roi, click_to_dep, etc.) are returned as numbers in the 0..1 range, money in USD.
POST /api/stats/export/csv
The same StatsQueryDto body. The response is text/csv; charset=utf-8, file name stats-report-YYYY-MM-DD.csv. Pagination is ignored; the export is limited to 100,000 rows.
curl -X POST 'https://adset.pro/api/stats/export/csv' \
-H 'Authorization: Bearer pat_…' \
-H 'Content-Type: application/json' \
--data-binary @query.json -o report.csv
Reference data GET /api/stats/meta/*
The reference endpoints are the live source of keys: when a new metric appears in the platform, it is immediately available in meta/metrics. Responses have the form { "data": [ … ], "traceId" }; cache them on the integration side.
meta/metrics
{
"key": "roi",
"type": "calculated",
"title": "ROI",
"group": "Finance",
"format": "percent",
"dependencies": ["revenue", "cost"],
"table": "events"
}
type — direct (direct aggregate) or calculated (computed from dependencies); format — a formatting hint: ceil (integer), finance (money), percent (ratio 0..1), number; table — the ClickHouse table in which the metric exists.
meta/groups
{ "key": "cmp_campaign", "title": "Campaign", "group": "Campaign", "tables": ["events", "events_push", "events_push_attributed"] }
tables — the tables in which the grouping is valid; groupings and metrics in one request must share at least one table.
meta/filters
{ "field": "user_country", "type": "list", "group": "Traffic", "name": "Country" }
meta/distinct
Field value suggestions: GET /api/stats/meta/distinct?field=user_country&q=us&limit=20. The field must be in meta/filters.
{
"data": [
{ "label": "US", "value": "US" },
{ "label": "Australia", "value": "AU" }
],
"traceId": "01HX…"
}
For entities (cmp_campaign, cmp_offer, cmp_cpa…) value is the ObjectId and label is the name. The same endpoint is handy for finding an id for a filter by name.
meta/os-versions
Same as distinct?field=user_os_ver, but with additional OS version normalization.
Examples
Report by day and campaign for last week
curl -X POST 'https://adset.pro/api/stats/query' \
-H 'Authorization: Bearer pat_…' \
-H 'Content-Type: application/json' \
-d '{
"time": { "preset": "prevWeek", "timezone": "Europe/Moscow" },
"groups": ["day", "cmp_campaign"],
"metrics": ["clicks", "cpa_accept", "revenue", "roi"],
"filters": [
{ "field": "user_country", "op": "in", "value": ["US","CA","GB"] }
],
"pagination": { "page": 1, "limit": 50 },
"sort": { "field": "revenue", "order": "desc" }
}'
Country suggestions
curl -G 'https://adset.pro/api/stats/meta/distinct' \
-H 'Authorization: Bearer pat_…' \
--data-urlencode 'field=user_country' \
--data-urlencode 'q=u' \
--data-urlencode 'limit=10'
Weekly LTV cohort
curl -X POST 'https://adset.pro/api/stats/query' \
-H 'Authorization: Bearer pat_…' \
-H 'Content-Type: application/json' \
-d '{
"time": { "preset": "last30" },
"groups": ["cohort_week", "lifetime_days"],
"metrics": ["ftds", "ltv_d0", "ltv_d1_7", "ltv_d8_30", "ltv_total", "ltv_per_ftd"],
"pagination": { "page": 1, "limit": 1000 }
}'
Push Attribution with a 48-hour window
curl -X POST 'https://adset.pro/api/stats/query' \
-H 'Authorization: Bearer pat_…' \
-H 'Content-Type: application/json' \
-d '{
"time": { "preset": "last7" },
"groups": ["day", "event_push_id"],
"metrics": ["push_views", "push_clicks", "push_postclick_accepts", "push_click_to_accept_rate"],
"attributionWindow": { "hours": 48, "eventType": "click" }
}'
CSV export
curl -X POST 'https://adset.pro/api/stats/export/csv' \
-H 'Authorization: Bearer pat_…' \
-H 'Content-Type: application/json' \
--data-binary @query.json -o report.csv
Errors
| HTTP | When |
|---|---|
400 time is required |
time is not passed |
400 time.preset or time.from/time.to required |
time has neither preset nor from |
422 validationError |
invalid date format, unknown op, metric or grouping; details are in details[] |
403 forbidden + Insufficient OAuth scope. Required: api:stats… |
the token lacks the required scope (for example, a PAT without api:stats:export calls CSV) |
429 |
the 3 requests/s limit on /api/stats/** is exceeded |
The general error format and 401/403 codes are described in the section's main article.
Related articles
- Statistics: field reference — all filter, grouping and metric keys
- Metrics reference — what each metric means and how to read it
- Adset MCP service — the same reports via LLM clients
