the API
Do everything with code
Manage sites, read every metric, follow visitor journeys, pull SEO moves and export raw events, all over a plain REST API. Same data as your dashboard. This page covers what every request has in common: the base URL, authentication, periods and filters, limits, and errors.
Base URL
Every endpoint lives under:
https://datalenk.com/api/v1
JSON in, JSON out, with camelCase fields.
Quickstart
1. Create a key in Dashboard, API. Copy it once (you will not see it again). 2. Send your first request:
curl https://datalenk.com/api/v1/sites \ -H "Authorization: Bearer dlk_live_YOUR_KEY"
3. You get JSON back:
{
"data": [
{ "id": 3, "domain": "myshop.com", "installed": true,
"category": "ecommerce", "tags": [], "timezone": "Europe/Paris",
"createdAt": "2026-06-27T13:04:56.726Z" }
]
}Authentication
Every request carries an API key in the Authorization header. Keys are created and revoked in Dashboard, API.
Authorization: Bearer dlk_live_xxxxxxxxxxxxxxxxxxxx
Keep keys server-side, in an environment variable. Never ship a key in front-end code or a public repo.
Scopes
Each key carries one or more scopes. Grant only what an integration needs.
read: all GET endpoints: stats, visitors, SEO, listings.write: create and modify: sites, goals, funnels.export: bulk export of raw events and payments.
Rotation
To rotate, create a new key, deploy it, then revoke the old one. Revoked keys are refused immediately.
When auth fails
A missing, invalid or revoked key returns 401; a valid key without the needed scope returns 403.
{ "error": { "code": "unauthorized",
"message": "Invalid or revoked API token. Manage your keys in Dashboard, API." } }Periods and filters
Read endpoints accept either a relative range or an absolute window.
?range=: today, yesterday, 7d, 30d, 90d, wtd, mtd, or a number of days.?from=&to=: absolute dates (YYYY-MM-DD).?grain=: hour, day, week or month (for timeseries).
curl "https://datalenk.com/api/v1/sites/3/stats/summary?range=30d" -H "Authorization: Bearer dlk_live_…" curl "https://datalenk.com/api/v1/sites/3/stats/timeseries?from=2026-06-01&to=2026-06-30&grain=day" -H "Authorization: Bearer dlk_live_…"
Cross-filter any dataset with ?filter[dim]=value. Dimensions: channel, referrer, country, device, browser, os, region, city, language, campaign, source, page.
curl "https://datalenk.com/api/v1/sites/3/stats/pages?filter[channel]=Organic%20Search" -H "Authorization: Bearer dlk_live_…"
Pagination and limits
Dimension datasets accept ?limit= (default 50, max 200). Exports stream and page internally with a temporal cursor.
Rate limits
- Reads: 600 requests / minute.
- Writes: 300 requests / minute.
- Exports: 20 requests / hour.
Over the limit returns 429 with a Retry-After header. Read endpoints are cached for 60 seconds, so polling more often than that returns the same answer.
Errors
Every error is a JSON object { error: { code, message, docs? } }. The code is stable; the message says what to fix.
{ "error": { "code": "plan_limit",
"message": "Plan site limit reached. Upgrade your plan or delete a site to add more.",
"docs": "https://datalenk.com/docs/api/sites" } }| Code | HTTP | Meaning and fix |
|---|---|---|
| unauthorized | 401 | Missing, invalid or revoked API key. Create one in Dashboard, API. |
| forbidden | 403 | The key lacks the required scope (read / write / export). Grant it in Dashboard, API. |
| invalid_request | 400 | Malformed body or query. The message names the offending field. |
| not_found | 404 | The site, funnel or visitor does not exist in your workspace. |
| plan_limit | 403 | Your plan's site limit is reached. Upgrade or delete a site. |
| gsc_not_connected | 404 | Search Console is not connected for the site (SEO reports). |
| rate_limited | 429 | Too many requests. Back off; a Retry-After header tells you how long. |
| conflict | 409 | The resource is in a state that blocks the operation. |
| internal | 500 | Something failed on our side. Retry; if it persists, contact support. |
Resources
- →Sites Add, update and delete sites. Get the install snippet.
- →Stats Traffic, revenue, channels, pages, devices, keywords with attributed revenue, Web Vitals.
- →SEO Opportunities, cannibalization, AI-answer theft, brand split.
- →Exports Stream raw events and payments as CSV or NDJSON.
- →Ingestion Send events, payments, identify users, push tracked-link metadata.
Prefer an AI agent?
Datalenk also exposes an MCP server at https://datalenk.com/api/mcp. Plug Claude or ChatGPT straight onto your data with the same API key: it can add a site, install the tracker, declare goals and funnels, then analyse the result without leaving the conversation. See MCP server.