# REST API

This is the markdown version of https://statlark.com/docs/api. Every docs and Learn page has one: add .md to its address. Index: https://statlark.com/llms.txt

An HTTP API for your Statlark data — pull revenue, visitors and traffic sources into a script, spreadsheet or LLM, and push conversions, revenue and identity straight from your own server.

The base URL is `https://app.statlark.com/api/v1`. Every response is JSON. Every request needs a bearer token, which reads one site or every site in your workspace. Prefer machine-readable? There’s an [OpenAPI 3.1 spec](https://statlark.com/api/v1/openapi.json) and an [llms.txt](https://statlark.com/llms.txt) index.

Prefer asking an AI assistant? Claude, ChatGPT, Cursor and other assistants can sign in to the [MCP server](https://statlark.com/docs/mcp.md), or use the same keys, and answer questions about your revenue in plain language. Working in a terminal? The [command line](https://statlark.com/docs/cli.md) reads these endpoints for you, and for AI coding agents.

## Authentication

Create a token under [Settings → API keys](https://statlark.com/settings). Choose **This site only** for a key that reads one site, or **All sites in this workspace** for one that reads every site in it. Writes are pinned to one site, so they need a single-site key. The full token (`slk_…`) is shown **once**, at creation — copy it then; Statlark stores only a hash and can’t show it again. Lost it? Revoke it and create another.

Send it in the `Authorization` header on every request. Treat it like a password: it’s meant for server-side use — don’t embed it in a web page or app you ship to users.

Each token carries one or more **permissions**, chosen when you create it: `analytics:read` for the read endpoints below, `ingest:write` for the payments, goals and identify endpoints, and `bots:write` for `POST /bots`. A fourth, `people:read`, lets the [MCP server](https://statlark.com/docs/mcp.md) show people’s names, emails and lifetime value; the REST API doesn’t use it today. A call needs a token with the matching permission or it returns `403`.

```bash
curl "https://app.statlark.com/api/v1/overview?site=sl_xxxx&from=2026-06-01&to=2026-07-01" \
  -H "Authorization: Bearer slk_your_token_here"
```

## <a id="parameters"></a>Common parameters

Every read endpoint except [sites](https://statlark.com/docs/api.md#sites) takes `site`. The **ranged** endpoints also take `from`/`to`; the “now” and metadata endpoints ([realtime](https://statlark.com/docs/api.md#realtime), [site](https://statlark.com/docs/api.md#site), and the [goals](https://statlark.com/docs/api.md#goals-read) list) take only `site`.

- `site` — your site id (`sl_…`), the same value on your tracker snippet. Required. A single-site token reads only its own site, and a workspace token any site in its workspace; any other id returns `403`.
- `from` and `to` — the window, as an ISO date (`YYYY-MM-DD`) or full timestamp. Required on the ranged endpoints. The range is interpreted in **UTC** and is half-open `[from, to)` — `from` is included, `to` is not. The one exception is [keywords](https://statlark.com/docs/api.md#keywords), where a bare date is a calendar day in the site’s timezone. The window can span at most **366 days** per request.

## Overview

`GET /api/v1/overview` — the headline metrics: revenue, visitors, paying conversion, revenue-per-visitor, sessions, bounce rate and session length, each with the value for the preceding equal-length period (so you can compute a delta). `bounce_rate` runs from 0 to 1, `avg_session_seconds` is in whole seconds, and both are `null` for a window with no [sessions](https://statlark.com/docs/reading-your-data.md#sessions). It also returns `unattributed_revenue`: revenue from payments with no visitor attached, which has no previous-period value. `revenue` minus `unattributed_revenue` is what every [sources](https://statlark.com/docs/api.md#sources) grouping and the [breakdowns](https://statlark.com/docs/api.md#breakdowns) `totals.revenue` add up to. Bot hits are left out of every number, and a Stripe renewal records revenue without making the customer a visitor for the window. `hidden_visitors` is the number of visitors in the window left out by the site’s [email exclusion rules](https://statlark.com/docs/excluding-traffic.md#hide-app-test-devices): devices that signed in with an address the owner chose to hide. It’s 0 when there are none. Every other figure here already leaves them out; revenue never does.

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-07-01T00:00:00.000Z" },
  "metrics": {
    "revenue": 4820.5,
    "previous_revenue": 3905,
    "visitors": 12500,
    "previous_visitors": 11000,
    "paying_conversion": 0.02144,
    "previous_paying_conversion": 0.019,
    "revenue_per_visitor": 0.38564,
    "previous_revenue_per_visitor": 0.355,
    "sessions": 15200,
    "previous_sessions": 13100,
    "bounce_rate": 0.5125,
    "previous_bounce_rate": 0.5375,
    "avg_session_seconds": 125,
    "previous_avg_session_seconds": 118,
    "unattributed_revenue": 0,
    "hidden_visitors": 0
  }
}
```

## <a id="timeseries"></a>Revenue timeseries

`GET /api/v1/timeseries` — revenue over time, gap-filled into buckets in the site’s timezone. The optional `bucket` parameter is one of `hour`, `day` (default), `week` or `month`.

```bash
curl "https://app.statlark.com/api/v1/timeseries?site=sl_xxxx&from=2026-06-01&to=2026-06-04&bucket=day" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-06-04T00:00:00.000Z" },
  "bucket": "day",
  "points": [
    { "bucket_start": "2026-06-01T00:00:00+00:00", "revenue": 149.7 },
    { "bucket_start": "2026-06-02T00:00:00+00:00", "revenue": 0 },
    { "bucket_start": "2026-06-03T00:00:00+00:00", "revenue": 99.8 }
  ]
}
```

## <a id="sources"></a>Traffic sources

`GET /api/v1/sources` — your traffic sources ranked by revenue, each with visitors, revenue-per-visitor and paying conversion. The optional `grouping` parameter is one of `channel` (default), `utm_source`, `referrer` or `adclick`. A source’s revenue includes customers who paid in the window without visiting (credited to their first touch), so a row can have `visitors: 0` with revenue; its `revenue_per_visitor` and `paying_conversion` are then `null`.

```bash
curl "https://app.statlark.com/api/v1/sources?site=sl_xxxx&from=2026-06-01&to=2026-07-01&grouping=channel" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-07-01T00:00:00.000Z" },
  "grouping": "channel",
  "sources": [
    {
      "source": "Organic",
      "visitors": 3072,
      "revenue": 1152,
      "revenue_per_visitor": 0.375,
      "paying_conversion": 0.0078125
    }
  ]
}
```

## Breakdowns

`GET /api/v1/breakdowns` — audience breakdowns for the window: countries, cities, devices, browsers, operating systems, hostnames and `visitor_types` (`new` or `returning`), each row with visitors, attributed revenue and revenue-per-visitor. A dimension holds at most 10 rows: the top 8 keys by visitors (ties broken by revenue, then key), then an `Unknown` row for visitors with no value, then an `Other` row aggregating rank 9 and below. `Unknown` and `Other` always sort last, however large they are — and on `devices` the lower-case `unknown` key (an unreadable user agent) is a separate row from `Unknown`. As on sources, a row’s `revenue_per_visitor` is `null` when it has revenue but no visitors. (Per-row paying conversion isn’t available here — use [sources](https://statlark.com/docs/api.md#sources) for conversion.)

```bash
curl "https://app.statlark.com/api/v1/breakdowns?site=sl_xxxx&from=2026-06-01&to=2026-07-01" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-07-01T00:00:00.000Z" },
  "totals": { "visitors": 6400, "revenue": 2480, "identified": 512, "customers": 48 },
  "countries": [
    { "key": "US", "visitors": 3072, "revenue": 1536, "revenue_per_visitor": 0.5 },
    { "key": "GB", "visitors": 1024, "revenue": 384, "revenue_per_visitor": 0.375 },
    { "key": "DE", "visitors": 512, "revenue": 192, "revenue_per_visitor": 0.375 },
    { "key": "CA", "visitors": 384, "revenue": 96, "revenue_per_visitor": 0.25 },
    { "key": "FR", "visitors": 256, "revenue": 64, "revenue_per_visitor": 0.25 },
    { "key": "AU", "visitors": 192, "revenue": 48, "revenue_per_visitor": 0.25 },
    { "key": "RO", "visitors": 128, "revenue": 32, "revenue_per_visitor": 0.25 },
    { "key": "NL", "visitors": 96, "revenue": 24, "revenue_per_visitor": 0.25 },
    { "key": "Unknown", "visitors": 320, "revenue": 0, "revenue_per_visitor": 0 },
    { "key": "Other", "visitors": 416, "revenue": 104, "revenue_per_visitor": 0.25 }
  ],
  "cities": [
    { "key": "New York", "visitors": 1024, "revenue": 512, "revenue_per_visitor": 0.5 },
    { "key": "London", "visitors": 768, "revenue": 288, "revenue_per_visitor": 0.375 },
    { "key": "San Francisco", "visitors": 512, "revenue": 320, "revenue_per_visitor": 0.625 },
    { "key": "Berlin", "visitors": 384, "revenue": 96, "revenue_per_visitor": 0.25 },
    { "key": "Bucharest", "visitors": 256, "revenue": 112, "revenue_per_visitor": 0.4375 },
    { "key": "Unknown", "visitors": 3456, "revenue": 1152, "revenue_per_visitor": 0.3333333333333333 }
  ],
  "devices": [
    { "key": "desktop", "visitors": 3576, "revenue": 1344, "revenue_per_visitor": 0.37583892617449666 },
    { "key": "mobile", "visitors": 2560, "revenue": 1024, "revenue_per_visitor": 0.4 },
    { "key": "tablet", "visitors": 248, "revenue": 112, "revenue_per_visitor": 0.45161290322580644 },
    { "key": "unknown", "visitors": 8, "revenue": 0, "revenue_per_visitor": 0 },
    { "key": "Unknown", "visitors": 8, "revenue": 0, "revenue_per_visitor": 0 }
  ],
  "browsers": [
    { "key": "Chrome", "visitors": 3200, "revenue": 1200, "revenue_per_visitor": 0.375 },
    { "key": "Safari", "visitors": 2048, "revenue": 896, "revenue_per_visitor": 0.4375 },
    { "key": "Firefox", "visitors": 640, "revenue": 240, "revenue_per_visitor": 0.375 },
    { "key": "Edge", "visitors": 448, "revenue": 112, "revenue_per_visitor": 0.25 },
    { "key": "Unknown", "visitors": 64, "revenue": 32, "revenue_per_visitor": 0.5 }
  ],
  "os": [
    { "key": "Windows", "visitors": 2560, "revenue": 992, "revenue_per_visitor": 0.3875 },
    { "key": "iOS", "visitors": 1920, "revenue": 744, "revenue_per_visitor": 0.3875 },
    { "key": "Android", "visitors": 1216, "revenue": 456, "revenue_per_visitor": 0.375 },
    { "key": "macOS", "visitors": 640, "revenue": 240, "revenue_per_visitor": 0.375 },
    { "key": "Linux", "visitors": 64, "revenue": 48, "revenue_per_visitor": 0.75 }
  ],
  "hostnames": [
    { "key": "example.com", "visitors": 5120, "revenue": 2080, "revenue_per_visitor": 0.40625 },
    { "key": "app.example.com", "visitors": 1024, "revenue": 384, "revenue_per_visitor": 0.375 },
    { "key": "blog.example.com", "visitors": 256, "revenue": 16, "revenue_per_visitor": 0.0625 }
  ],
  "visitor_types": [
    { "key": "new", "visitors": 4800, "revenue": 960, "revenue_per_visitor": 0.2 },
    { "key": "returning", "visitors": 1600, "revenue": 1520, "revenue_per_visitor": 0.95 }
  ]
}
```

## Pages

`GET /api/v1/pages` — pages ranked by pageviews, each with its title, visitors, entries, entry visitors, exits, exit and bounce rates, time on page, scroll, and landing-attributed revenue + revenue-per-landing-visitor. `entries`, `exits` and `bounce_rate` count [sessions](https://statlark.com/docs/reading-your-data.md#sessions), so `entries` are the sessions that started on the page. `visitors` counts everyone who viewed the page, and `entry_visitors` counts the visitors who started a session on it, so use `entry_visitors` for an entry page’s visitors; it never exceeds `entries`. `avg_time_seconds` and `avg_scroll_percent` are `null` when no pageview of the page sent the [leave signal](https://statlark.com/docs/script-configuration.md#leave-signal), and `title` is `null` until one carries a title. Set `entry_only=true` to restrict to pages where a session started; `entry_only` accepts `true`, `1` or `yes`. `revenue_per_landing_visitor` divides that revenue by the page’s *landing* visitors, not by the row’s `visitors`, and is `null` for a page that is no **range-active** visitor’s landing page (rather than `0`).

```bash
curl "https://app.statlark.com/api/v1/pages?site=sl_xxxx&from=2026-06-01&to=2026-07-01&entry_only=false" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-07-01T00:00:00.000Z" },
  "entry_only": false,
  "pages": [
    {
      "path": "/pricing",
      "title": "Pricing — Example",
      "pageviews": 4100,
      "visitors": 2600,
      "entries": 900,
      "entry_visitors": 610,
      "exits": 1200,
      "exit_rate": 0.2926829268292683,
      "bounce_rate": 0.4,
      "avg_time_seconds": 72,
      "avg_scroll_percent": 78,
      "revenue": 1899.5,
      "revenue_per_landing_visitor": 1.8264423076923078
    },
    {
      "path": "/blog/revenue-attribution",
      "title": "Revenue attribution — Example blog",
      "pageviews": 2380,
      "visitors": 1740,
      "entries": 1310,
      "entry_visitors": 1150,
      "exits": 1100,
      "exit_rate": 0.46218487394957986,
      "bounce_rate": 0.7099236641221374,
      "avg_time_seconds": 95,
      "avg_scroll_percent": 64,
      "revenue": 412.25,
      "revenue_per_landing_visitor": 0.2998181818181818
    },
    {
      "path": "/docs/api",
      "title": null,
      "pageviews": 960,
      "visitors": 610,
      "entries": 0,
      "entry_visitors": 0,
      "exits": 300,
      "exit_rate": 0.3125,
      "bounce_rate": null,
      "avg_time_seconds": null,
      "avg_scroll_percent": null,
      "revenue": 0,
      "revenue_per_landing_visitor": null
    }
  ]
}
```

## <a id="bots"></a>Bot traffic

`GET /api/v1/bots` — which crawlers requested the site, from [bot tracking](https://statlark.com/docs/bot-traffic.md) on your server. Filter with `category` (`ai_answers`, `indexing`, `training` or `other`), `company` and `page`. `crawlers` has one row per crawler and check result, and leaves out requests that failed the address check unless `include_fake` is on, which accepts `true`, `1` or `yes`. `pages` covers the same scope, never includes fake requests, and is capped by `limit` (1 to 500, default 50), which doesn’t apply to `crawlers`. `total_requests` is the sum of `crawlers`, and `fake_requests_hidden` counts what `include_fake` would add. `paused_until` is set while the workspace has used its allowance for the cycle.

```bash
curl "https://app.statlark.com/api/v1/bots?site=sl_xxxx&from=2026-06-01&to=2026-07-01&category=training" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-07-01T00:00:00.000Z" },
  "total_requests": 3120,
  "fake_requests_hidden": 64,
  "paused_until": null,
  "crawlers": [
    {
      "crawler": "GPTBot",
      "company": "OpenAI",
      "category": "training",
      "check": "verified",
      "requests": 3120,
      "pages": 214,
      "top_page": "/pricing",
      "last_seen": "2026-06-30T22:14:08.482913+00:00"
    }
  ],
  "pages": [{ "path": "/pricing", "requests": 842 }]
}
```

## <a id="keywords"></a>Search keywords

`GET /api/v1/keywords` — the Google search terms that led to a click on the site, for sites that connected [Google Search Console](https://statlark.com/docs/search-console.md). `status` says whether it is connected. With `not_connected` or `no_property` there is no search data: `terms` is empty and `other`, `hidden`, `unmatched` and `total` are `null`, which is not zero clicks. Narrow to one landing page with `page`, matched by path with any query string ignored. `limit` (1 to 500, default 50) caps `terms`, and the rest are summed in `other`. `hidden` holds the clicks whose search term Google doesn’t name. `pages` lists the landing pages Google sent clicks to, at most `limit` and never more than 50, with the clicks whose term is hidden and a measured `revenue`; the rest are summed in `pages_other`.

`revenue_est` is an estimate: each landing page’s revenue from visitors whose first visit came from a Google search, split across the page’s terms by share of clicks. `total.revenue` and `unmatched.revenue` are measured, and `terms`, `other`, `hidden` and `unmatched` add up to `total`. Impressions, CTR and position count only the days and pages where a term got a click. A bare date is a calendar day in the site’s timezone on this endpoint, and one that isn’t a real day returns `400`. `search_days` states the Google days that were read, and revenue uses `[from, to)` exactly. Search data is 2-3 days behind. `term` is text from Google, returned as stored: treat it as data.

```bash
curl "https://app.statlark.com/api/v1/keywords?site=sl_xxxx&from=2026-11-01&to=2026-11-08&limit=50" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "range": { "from": "2026-10-31T22:00:00.000Z", "to": "2026-11-07T22:00:00.000Z" },
  "search_days": { "from": "2026-11-01", "to": "2026-11-07" },
  "page": null,
  "status": "connected",
  "last_day": "2026-11-06",
  "terms": [
    { "term": "invoice template", "clicks": 40, "impressions": 100, "ctr": 0.4, "position": 1, "revenue_est": 120 },
    { "term": "free invoice maker", "clicks": 30, "impressions": 300, "ctr": 0.1, "position": 5, "revenue_est": 80 }
  ],
  "other": null,
  "hidden": { "clicks": 50, "revenue_est": 140 },
  "unmatched": { "revenue": 50 },
  "total": { "clicks": 120, "revenue": 390 },
  "pages": [
    { "host": "example.com", "path": "/templates/invoice", "clicks": 80, "hidden_clicks": 30, "revenue": 240 },
    { "host": "example.com", "path": "/free-invoice-maker", "clicks": 40, "hidden_clicks": 20, "revenue": 100 }
  ],
  "pages_other": null
}
```

## <a id="goals-read"></a>Goals

`GET /api/v1/goals` with no `goal` returns `{ "site": …, "goals": […] }` — an object, not a bare array — listing every goal name ever recorded for the site (except goals only bots recorded); `from`/`to` are ignored on that branch, so it spans all time. Add `goal=<name>` with a `from`/`to` window to get that goal’s conversions over time and its conversion rate by entry page; the optional `bucket` is one of `hour`, `day` (default), `week` or `month`. `conversions_by_landing` covers the landing page of **every** visitor active in the window or converting on the goal, not only the ones that converted, and is uncapped — `landing_path` is the raw first-touch path, query string included. (Recording a conversion is a [write](https://statlark.com/docs/api.md#writing): `POST /api/v1/goals`.)

```bash
# List every goal recorded for the site
curl "https://app.statlark.com/api/v1/goals?site=sl_xxxx" \
  -H "Authorization: Bearer slk_your_token_here"

# One goal's conversions over time + a rate for every entry page
curl "https://app.statlark.com/api/v1/goals?site=sl_xxxx&goal=signup&from=2026-06-01&to=2026-06-04&bucket=day" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "goal": "signup",
  "range": { "from": "2026-06-01T00:00:00.000Z", "to": "2026-06-04T00:00:00.000Z" },
  "bucket": "day",
  "timeseries": [
    { "bucket_start": "2026-06-01T00:00:00+00:00", "conversions": 18 },
    { "bucket_start": "2026-06-02T00:00:00+00:00", "conversions": 9 },
    { "bucket_start": "2026-06-03T00:00:00+00:00", "conversions": 13 }
  ],
  "conversions_by_landing": [
    { "landing_path": "/pricing", "landing_visitors": 900, "conversions": 34, "conversion_rate": 0.03777777777777778 },
    { "landing_path": "/?utm_source=toolify", "landing_visitors": 240, "conversions": 6, "conversion_rate": 0.025 },
    { "landing_path": "/blog/revenue-attribution", "landing_visitors": 612, "conversions": 0, "conversion_rate": 0 }
  ]
}
```

## Realtime

`GET /api/v1/realtime` — the right-now snapshot: active visitors (distinct in the last 5 minutes) and the most recent events (last 30 minutes, newest first, capped at **50** — there’s no pagination and no truncation flag, so a busy site’s feed is incomplete). No `from`/`to` — it’s always “now”.

```bash
curl "https://app.statlark.com/api/v1/realtime?site=sl_xxxx" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "active_visitors": 7,
  "recent_events": [
    {
      "occurred_at": "2026-07-01T12:04:11.812431+00:00",
      "type": "pageview",
      "name": null,
      "path": "/pricing",
      "country": "US",
      "region": "CA",
      "city": "San Francisco",
      "channel": "Organic",
      "visitor_id": "b1e8f0a2-4c77-4b3e-9a51-2f0d6c8ea310"
    }
  ]
}
```

## Sites

`GET /api/v1/sites` — the sites this token can read, with each one’s id, domain, timezone and currency, sorted by domain, plus the token’s own `scopes`. A single-site token lists its one site and a workspace token every site in its workspace. It takes no parameters, needs `analytics:read`, and is the one read that answers even when the workspace has no plan, so a script can tell which site a `402` is about.

```bash
curl "https://app.statlark.com/api/v1/sites" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "key": { "scopes": ["analytics:read"] },
  "sites": [
    { "id": "sl_xxxx", "domain": "example.com", "timezone": "America/New_York", "currency": "USD" },
    { "id": "sl_yyyy", "domain": "shop.example.com", "timezone": "Europe/Bucharest", "currency": "EUR" }
  ]
}
```

## <a id="site"></a>Site metadata

`GET /api/v1/site` — the config the other endpoints report against: domain, timezone, currency and the #1 KPI goal. No `from`/`to`.

```bash
curl "https://app.statlark.com/api/v1/site?site=sl_xxxx" \
  -H "Authorization: Bearer slk_your_token_here"
```

```json
{
  "site": "sl_xxxx",
  "domain": "example.com",
  "timezone": "America/New_York",
  "currency": "USD",
  "primary_kpi_goal": "signup"
}
```

## <a id="writing"></a>Writing data server-side

Send conversions, revenue and identity straight from your own server, so they survive ad blockers and become the source of truth. These endpoints need a token with the `ingest:write` permission (Bot traffic, below, needs `bots:write` instead); each is a `POST` (or `DELETE`) with a JSON body, and always writes to the token’s own site. Attribute a hit to a visitor by including the `visitor_id` you captured client-side with [`statlark.getVisitorId()`](https://statlark.com/docs/script-configuration.md).

### Payments

`POST /api/v1/payments` — record revenue from any provider (Stripe, LemonSqueezy, Polar, Paddle…). **Idempotent** on `transaction_id`, so retries are safe: `created` is `true` on the insert and `false` for a duplicate. `amount` is a JSON number in major units (e.g. `49.00`, not `4900`) **and must be greater than 0 after rounding to two decimals**.

Also accepted: `customer_email` (stitches the sale to a person and, with no `visitor_id`, credits it to their first visit), `session_id`, `provider` (defaults to `api`), `occurred_at` (an ISO date or timestamp; defaults to now) and `raw` — your provider’s original payload, which must be a JSON *object* and at most 16,384 bytes. `currency` defaults to `USD` and must be a three-letter code. Send one that isn’t the site’s configured currency and the call still returns `created: true`, but the payment is excluded from every revenue figure rather than converted.

```bash
curl -X POST "https://app.statlark.com/api/v1/payments" \
  -H "Authorization: Bearer slk_your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_id": "ch_3Q7...",
    "amount": 49.00,
    "currency": "USD",
    "visitor_id": "b1e8f0a2-...",
    "customer_email": "jo@example.com"
  }'
```

```json
{ "ok": true, "created": true }
```

### Refunds

To net a refund out of your revenue, `POST` to the same `/api/v1/payments` endpoint with a `refunded_amount` instead of an `amount`. It’s matched to the original sale by `transaction_id` and subtracted from revenue everywhere — Overview, sources, pages and each customer’s lifetime value. `refunded_amount` is the **cumulative** total ever refunded on that transaction (in major units), so it’s safe to send the same value twice — the call is idempotent and never lowers a larger refund already recorded. A refund is credited against the original sale’s date, so it appears in any report window that contains the *purchase*. Optionally send a `status` (`refunded`, `partially_refunded` or `disputed`); omit it and Statlark derives it from the amounts. If no payment carries that `transaction_id`, you get a `404`.

```bash
curl -X POST "https://app.statlark.com/api/v1/payments" \
  -H "Authorization: Bearer slk_your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_id": "ch_3Q7...",
    "refunded_amount": 49.00
  }'
```

```json
{
  "ok": true,
  "matched": true,
  "transaction_id": "ch_3Q7...",
  "amount": 49,
  "refunded_amount": 49,
  "net_amount": 0,
  "status": "refunded"
}
```

### Deleting a payment

`DELETE /api/v1/payments` — erase one recorded payment by `transaction_id` and recompute the affected customer’s lifetime value. Use it to correct a mis-recorded sale, or to honor a data deletion request. Returns `404` if nothing matches. (To net a refund, prefer the refund call above — `DELETE` removes the sale entirely, as if it never happened.)

```bash
curl -X DELETE "https://app.statlark.com/api/v1/payments" \
  -H "Authorization: Bearer slk_your_token_here" \
  -H "Content-Type: application/json" \
  -d '{ "transaction_id": "ch_3Q7..." }'
```

```json
{ "ok": true, "deleted": true }
```

### Goals

`POST /api/v1/goals` — the server-side twin of `statlark.goal()`. Needs the `visitor_id` and a `name`; optional `props` are capped like everywhere else (≤20 keys, primitive values). Unlike payments this write is **not idempotent** — there’s no dedupe key, so a retried webhook records a second conversion — and it can’t be backdated: the conversion is timestamped when it arrives.

```bash
curl -X POST "https://app.statlark.com/api/v1/goals" \
  -H "Authorization: Bearer slk_your_token_here" \
  -H "Content-Type: application/json" \
  -d '{ "visitor_id": "b1e8f0a2-...", "name": "signup", "props": { "plan": "pro" } }'
```

```json
{ "ok": true }
```

### Identify

`POST /api/v1/identify` — attach a `user_id`, `user_email` and `traits` to a visitor for cross-device, revenue-tied identity. Only the fields you send are updated, so a call carrying just new traits won’t clear an existing email — but a field sent explicitly as `null`, `""` or any non-string *does* clear it. `traits` replaces the stored traits wholesale rather than merging, and is capped the same way as goal props.

```bash
curl -X POST "https://app.statlark.com/api/v1/identify" \
  -H "Authorization: Bearer slk_your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "visitor_id": "b1e8f0a2-...",
    "user_id": "user_123",
    "user_email": "jo@example.com",
    "traits": { "plan": "pro" }
  }'
```

```json
{ "ok": true }
```

### <a id="bots-write"></a>Bot traffic

`POST https://collect.statlark.com/bots` reports a crawler’s request. It runs on its own host, not `app.statlark.com`, and needs a single-site key with the `bots:write` permission, which is a secret because you supply the crawler’s IP address. The answer is always `200` unless the key, the plan or the body is wrong: check `recorded`, and `reason` when it’s false. Only send requests that look like crawlers. The [bot tracking guide](https://statlark.com/docs/bot-traffic.md#any-server) has the filter, and `@statlark/bots` does all of this for you.

```bash
curl -X POST https://collect.statlark.com/bots \
  -H "Authorization: Bearer $STATLARK_BOT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/pricing","user_agent":"GPTBot/1.1","ip":"132.196.86.10"}'
```

## Rate limits

Two limits protect the API. Each request is capped at **600 per minute per IP address** and, once authenticated, **300 per minute per token**. Both are token buckets: you can burst up to the limit, then draw down at the sustained rate (10 and 5 requests per second respectively). These ceilings are generous for normal use — polling, dashboards, server-side ingestion — and exist to absorb runaway loops and abuse.

Every `200` and every `429` carries your current quota — `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` (seconds until the bucket refills) — so you can slow down *before* you hit the ceiling rather than after. The other error statuses (`400`, `401`, `402`, `403`, `404`, `500`) carry none of the three. And when the per-IP limit is what tripped, the headers describe that IP bucket (`600`), not your per-token quota. `POST /bots` runs on a separate host and sends none of them: on a `429`, wait for its `Retry-After` header.

Exceed either limit and the request returns `429` with those same headers plus `Retry-After` (seconds to wait). Back off and retry after `Retry-After`; if you’re hitting these regularly, batch your calls or [get in touch](mailto:hello@statlark.com) and we’ll raise them.

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 1
X-RateLimit-Limit: 300
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 60

{ "error": "Rate limit exceeded — slow down and retry shortly." }
```

## Errors

Errors come back with the matching HTTP status and a JSON body of the shape below. `400` means a parameter or body field is missing or invalid; `401` means the token is missing, malformed or revoked; `402` means the site’s workspace has no active plan — its trial ended without a card or its subscription ended — so reads other than [sites](https://statlark.com/docs/api.md#sites) are refused and writes record nothing until an owner chooses a plan (see [Without a plan](https://statlark.com/docs/billing.md#without-a-plan); going over your event allowance never causes it); `403` means the token lacks the permission the call needs, or can’t read the requested site; `404` means the record you addressed is gone — no payment carries that `transaction_id`, or the site row was deleted mid-request; `429` means you’ve hit a rate limit (see above); `500` means the query or the token lookup failed on our side, and retrying a read is safe.

```json
{ "error": "This token can't read that site." }
```

The `402` message differs for reads and writes. Reads return `This workspace has no active plan. Choose one in Settings → Plan & billing.` and writes return `This workspace has no active plan, so tracking is stopped. Choose one in Settings → Plan & billing.` Either way, retrying won’t help until a plan is active again.

Amounts are in the site’s configured currency, as major units (e.g. dollars, not cents) — a payment recorded in any other currency is left out of revenue entirely, never converted. Every response is JSON and served `no-store` — these are live numbers, never cached at the edge.

Last reviewed 25 November 2026
