Reporting script
Pull last week's summary and top pages for one website, and stop when any part is missing.
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/websitesMatch 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.mjsIt 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" }
]
}Read the numbers right
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
Log the requestId from every failure so support can trace it.
Related
How is this guide?