API reference

Reporting script

Pull last week's summary and top pages for one website, and stop when any part is missing.

  1. Read-only key
  2. Find the website ID
  3. Query last week
  4. Check every result
  5. Report

Make a read-only key

In Organization settings → API keys, add a key with the Analytics preset (read:data), limited to the one website. Store it as DATABUDDY_API_KEY on your server, never in browser code.

Find the website ID

curl --fail-with-body -H "x-api-key: $DATABUDDY_API_KEY" \
  https://api.databuddy.cc/v1/query/websites

Match the website by name and domain, then save its id as DATABUDDY_WEBSITE_ID. Don't take the first one: a key can reach several websites. An empty list means the key has no website access, not that there's no traffic.

Query last week

curl --fail-with-body -X POST \
  -H "x-api-key: $DATABUDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "parameters": [
      { "name": "summary_metrics", "id": "overview" },
      { "name": "top_pages", "id": "pages" }
    ],
    "preset": "last_week",
    "limit": 10
  }' \
  "https://api.databuddy.cc/v1/query?website_id=$DATABUDDY_WEBSITE_ID&timezone=Europe/Berlin"

last_week is the previous Sunday to Saturday in the timezone you pass, UTC by default. The ids let your code find each result even if the order changes.

Run the checked script

Download query-analytics.mjs. It has no dependencies and runs with Bun or Node.js 22+.

DATABUDDY_TIMEZONE=Europe/Berlin bun query-analytics.mjs

It prints JSON only when both results succeed, and exits non-zero on a failed, missing or duplicated result. It doesn't retry, so your scheduler decides when to try again.

Tell a failure from an empty week

{
  "success": true,
  "data": [
    { "parameter": "overview", "success": true, "data": [] },
    { "parameter": "pages", "success": false, "data": [], "error": "Query execution failed" }
  ]
}
ResultMeansReport it as
success: falseThat query failedMissing. Never as zero.
success: true, empty dataNo matching data in that rangeEmpty, then check the website ID, dates and filters
success: true, rowsReal numbersThe numbers

Read the numbers right

FieldQuery typeNote
unique_visitorssummary_metricsThe website's visitors for the week
nametop_pagesThe page path
visitorstop_pagesVisitors to that page. People who saw several pages count on each, so don't add these up.

limit: 10 gives a shortlist, not every page. Compare one week with the dashboard in the same timezone before you schedule the report.

Handle errors in a scheduled run

StatusDo
401, 403Fix the key or its website access
402The plan doesn't include that query type; more scopes won't help
400Fix the request; don't resend it unchanged
429Wait Retry-After seconds, then retry with backoff

Log the requestId from every failure so support can trace it.

How is this guide?