Adset.ProAdset.ProKnowledge base
To app
Home/Public HTTP API/Statistics: reports and export

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 with 429.

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" },
  "currency": "EUR"               // not set — USD
}

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}
currency string no Currency of money metrics — an uppercase ISO 4217 code (EUR). Defaults to USD. See the “Currency” section below

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

  • groups and metrics accept only keys from the reference catalogs; an unknown key results in a 422 error.
  • 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.
  • attributionWindow affects only Push Attribution metrics (push_postclick_*); without it these metrics return zeros.
  • LTV/Cohort metrics (ltv_*, ftds, registrations…) are used together with the cohort_*, reg_cohort_*, lifetime_days* groupings.
  • For query, limit ≤ 10 000 is recommended; use CSV for a full export.

Currency

Money (cost, revenue, LTV and the metrics calculated from them — profit, epc, cpl…) is returned in USD by default. To get it in another currency, pass currency:

  • The available currencies are the ones the platform shows statistics in: currently USD, EUR, CNY, RUB. The list matches the “Currency” field in profile settings. A code outside the list results in a 400 error.
  • The API does not apply the profile or team currency on its own: without currency the response is always in USD, just as without timezone it is in UTC.
  • Each day is converted at its own rate — the one published the day before. So amounts by day, week and month add up and do not change along with the current rate.
  • Ratios (roi, click_to_dep…) do not depend on the currency.
  • The response currency is in meta.currency. The meta.fxRatesFrom field is the first day the currency has a rate for; money for earlier days is returned as zero. For USD, fxRatesFrom is null.

More on conversion and rates — in the article Statistics currency.

Response example

{
  "data": {
    "data": [
      {
        "day": "2026-05-13 00:00:00",
        "cmp_campaign": "65f0…",
        "cmp_campaign_name": "Brand A — RU",
        "clicks": 18432,
        "cpa_accept": 122,
        "revenue": 2840.55,
        "cost": 2088.64,
        "roi": 0.36
      }
      // … the remaining rows of the page
    ],
    "page": 1,
    "limit": 100,
    "total": 37,
    "totals": { "clicks": 412906, "cpa_accept": 2731, "revenue": 61904.2, "cost": 47618.62, "roi": 0.3 }
  },
  "meta": { "currency": "EUR", "fxRatesFrom": "2025-11-18" },
  "traceId": "01HX…"
}

Response fields:

  • data.data — rows of the current page: grouping keys and metrics. A calculated metric comes with the metrics it is computed from: in the example, cost was not requested but arrived together with roi.
  • data.page, data.limit — page number and page size.
  • data.total — the number of rows in the whole selection regardless of pagination.
  • data.totals — metric totals for the whole selection. Calculated metrics (roi, click_to_dep…) are recomputed from the total sums rather than added up row by row.
  • If the totals could not be calculated, the total and totals fields are absent and the rows are returned as usual.
  • Time groupings are returned in the request time zone: day, hourTime and tenMin as a YYYY-MM-DD HH:mm:ss string, week and month as a YYYY-MM-DD date, hour as a number from 0 to 23.

Ratios (roi, click_to_dep, etc.) are returned as numbers in the 0..1 range, money in the currency from meta.currency (USD by default).

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. The currency of money is in the X-Currency response header. Cells that start with =, +, -, @, a tab or a carriage return and are not a number are exported with a ' prefix — protection against formula execution in Excel/Google Sheets (CSV injection); numbers, including negative ones, are not changed.

curl -X POST 'https://app.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://app.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://app.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://app.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://app.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://app.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
400 currency must be an active system currency currency is not in the list of statistics currencies
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