API reference

SQL

Run your own SELECT across one or more websites when no query type answers your question.

curl https://api.databuddy.cc/sql/query \
  -H "x-api-key: $DATABUDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "websiteId": "'"$DATABUDDY_WEBSITE_ID"'",
    "sql": "SELECT path, count() AS pageviews, uniq(anonymous_id) AS visitors FROM analytics.events WHERE event_name = '\''screen_view'\'' AND time >= {from:DateTime} GROUP BY path ORDER BY pageviews DESC",
    "params": { "from": "2026-11-01 00:00:00" },
    "limit": 1000
  }'
{
  "columns": [
    { "name": "path", "type": "String" },
    { "name": "pageviews", "type": "UInt64" },
    { "name": "visitors", "type": "UInt64" }
  ],
  "rows": [{ "path": "/", "pageviews": "1204", "visitors": "811" }],
  "truncated": false,
  "elapsedMs": 38
}

The key needs read:data for every website in the request. 64-bit integers and decimals come back as strings so they stay exact; parse them with Number or BigInt.

Write the request

FieldMeaning
websiteIdOne website. Send this or websiteIds.
websiteIds1 to 50 websites in the same organization
sqlRequired. One SELECT or WITH query in ClickHouse SQL, up to 50 KB.
paramsValues for {name:Type} placeholders, such as {from:DateTime}. With one website, websiteId and websiteDomain are filled in for you.
limitRows to return, 1 to 50,000. Default 10,000.
Response fieldMeaning
columnsEach column's name and ClickHouse type
rowsOne object per row, keyed by column name
truncatedtrue when there were more rows than limit
elapsedMsHow long the query ran

Compare websites

A query sees only the websites you name. Group by the website column to compare them, such as client_id on analytics.events:

{
  "websiteIds": ["FIRST_WEBSITE_ID", "SECOND_WEBSITE_ID"],
  "sql": "SELECT client_id, count() AS pageviews FROM analytics.events WHERE event_name = 'screen_view' GROUP BY client_id"
}

Join on the website columns too when matches must come from the same website.

Find tables and columns

curl https://api.databuddy.cc/sql/schema -H "x-api-key: $DATABUDDY_API_KEY"

GET /sql/schema lists every table and column you can read, with notes on how to count each one. SQL tables shows the same list. On analytics.events, pageviews have event_name = 'screen_view', rows are dated by time, and visitors are uniq(anonymous_id). Tables such as analytics.error_spans need a plan that includes their feature.

Stay within limits

LimitValue
Query shapeOne SELECT or WITH, with no comments, comma joins (FROM a, b) or table functions
Run time20 seconds
Data read5 GB or 100 million rows
Result size10 MB
Queries60 a minute per API key
At onceOne query per organization; the next waits up to 5 seconds

Narrow the date range, select fewer columns or aggregate when you hit a limit.

Fix errors

StatusCodeWhen
400BAD_REQUESTThe SQL is invalid, reads something you can't read, or hit a limit; message says which
401UNAUTHORIZEDThe key is missing, revoked or expired
402FEATURE_UNAVAILABLEYour plan doesn't include a table; data.feature and data.requiredPlan say which
403FORBIDDENThe key lacks read:data for a website, or it belongs to another organization
404NOT_FOUNDThe website doesn't exist
429RATE_LIMITEDWait Retry-After seconds
503SERVICE_UNAVAILABLEYour previous query is still running, or too many are; wait Retry-After seconds

How is this guide?