Day 6: API and Raw Data
Goal: You query Plausible through the Stats API – metrics, breakdowns, filters –, analyse sequences directly in ClickHouse, where CE has no funnels, and fetch an export from the container. · Duration: approx. 60 min · Prerequisite: Day 5
Briefing
- The Stats API v2 is a single endpoint:
POST /api/v2/querywith a JSON body ofsite_id,metrics,date_range, and optionallydimensions,filtersandorder_by. The key is sent asAuthorization: Bearer …. - The API is read-only. In CE it cannot create sites, goals or users.
- What the API cannot do, SQL can: every event lives in ClickHouse.
windowFunnelbuilds a sequence across steps – the replacement for the funnels of the cloud version. - The export (Imports & exports) delivers daily totals as CSV files in a ZIP – meant for moving to another Plausible instance, not as a raw data export.
curl ── POST /api/v2/query {metrics, date_range, dimensions, filters} ──► JSON
Bearer <API key> (via Caddy: https://plausible.lab)
clickhouse-client ── SQL on events_v2 / sessions_v2 ──► everything, funnels too
Imports & exports ── Prepare download ──► ZIP in the container ──► docker compose cp
Drill 1: An API key
In the browser: click your name at the top right → Account
settings → API keys → New API
Key. Name it labor, copy the
suggested key, then click Create API key. The key is
shown only this once.
On the VM you store it in a file that only you can read (replace
<key> with the copied value):
# on argo
install -m 600 /dev/null ~/plausible/api-key
printf '%s\n' '<key>' > ~/plausible/api-key
Verify:
# on argo
stat -c '%a %s' ~/plausible/api-key
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","metrics":["visitors","pageviews"],"date_range":"day"}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" | jq -c '.results'Expected (your numbers will differ):
600 65
[{"metrics":[14,40],"dimensions":[]}]
The key belongs to your user and is valid for all sites you have access to. 64 characters plus the line ending.
Save your progress? Sign up for free
Drill 2: Metrics and time ranges
Five metrics for today, then a query for a fixed time range.
jq turns the arrays into a readable line.
# on argo
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","date_range":"day",
"metrics":["visitors","visits","pageviews","bounce_rate","visit_duration"]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" \
| jq -r '[.query.metrics, .results[0].metrics] | transpose[] | "\(.[0]): \(.[1])"'
H=$(date -u +%F)
Q='{"site_id":"itdrills.com","metrics":["visitors"],
"date_range":["'$H'","'$H'"]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" | jq -c '.query.date_range'Expected (numbers and date will differ):
visitors: 14
visits: 25
pageviews: 40
bounce_rate: 50
visit_duration: 31
["2026-11-20T00:00:00+00:00","2026-11-20T23:59:59+00:00"]
The API answers with the query as it understood it
(.query) – including the site’s time zone (UTC here) and
default values. bounce_rate is in percent,
visit_duration in seconds.
Save your progress? Sign up for free
Drill 3: Breakdowns
dimensions turns a single number into a table: per page,
per source, per goal.
# on argo
K=$(cat ~/plausible/api-key)
for d in event:page visit:source event:goal; do
echo "== $d"
Q='{"site_id":"itdrills.com","date_range":"day","metrics":["visitors"],
"dimensions":["'$d'"],"order_by":[["visitors","desc"]]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" \
| jq -r '.results[] | "\(.metrics[0])\t\(.dimensions[0])"'
doneExpected (abridged, numbers will differ):
== event:page
9 /books/sops/
6 /books/
4 /
3 /coming-soon/
== visit:source
12 Direct / None
2 newsletter
== event:goal
14 Buchseiten
5 Signup
1 Scroll 75% on /books/sops/
event:… are properties of individual events,
visit:… properties of the session (source, country,
browser, campaign). With event:goal as a dimension, only
conversions show up – the same list as in the dashboard.
Save your progress? Sign up for free
Drill 4: Filtering
Break it: Which plans do the people who sign up choose, and which page did they view last? First attempt:
# on argo
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","date_range":"day","metrics":["visitors"],
"dimensions":["event:props:plan"],
"filters":[["is","event:goals",["Signup"]]]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q"; echoExpected:
{"error":"#/filters/0: Invalid filter [\"is\", \"event:goals\", [\"Signup\"]]"}
Cause: A typo – the dimension is called
event:goal. The API validates every query against its
schema and names the location (#/filters/0).
Fix and verify:
# on argo
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","date_range":"day","metrics":["visitors"],
"dimensions":["event:props:plan"],
"filters":[["is","event:goal",["Signup"]]]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" \
| jq -r '.results[] | "\(.metrics[0])\t\(.dimensions[0])"'
curl -s -o /dev/null -w '%{http_code}\n' -H 'Authorization: Bearer falsch' \
-H 'Content-Type: application/json' https://plausible.lab/api/v2/query -d "$Q"Expected (numbers will differ):
3 pro
2 free
401
Filters are lists of operator, dimension and values (is,
is_not, contains, matches);
multiple filters are combined with AND. A wrong key returns
401 – the same error you get when the site does not match
the key.
Save your progress? Sign up for free
Drill 5: Sequences with SQL
How many visitors went from the book list to the SOPS page and signed
up there – in this order, within one hour? The cloud calls this a
funnel; ClickHouse has windowFunnel for it.
# on argo
cd ~/plausible/ce
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select level, count() as besucher from (
select user_id, windowFunnel(3600)(timestamp,
name = 'pageview' and pathname = '/books/',
name = 'pageview' and pathname = '/books/sops/',
name = 'Signup') as level
from events_v2 where timestamp >= today() group by user_id)
group by level order by level format TSV"Expected (numbers will differ):
0 8
1 5
2 1
level is the last step reached: 8 visitors never came in
via /books/, 5 saw the list but not the SOPS page
afterwards, one made it to the SOPS page. Nobody signed up along this
path – all signups landed directly on /books/sops/ (level
0). That is exactly what a funnel reveals: where the path breaks
off.
Save your progress? Sign up for free
Drill 6: The export
In the browser: Site settings → Imports & exports → Prepare download. Plausible builds the ZIP in the background and then wants to send an e-mail.
# on argo
cd ~/plausible/ce
sleep 10
docker compose logs plausible --since 2m 2>&1 | grep -m1 -o 'Mua.TransportError.*'
docker compose exec -T plausible ls /var/lib/plausible/plausible-exportsExpected:
Mua.TransportError) non-existing domain
1
The mail fails – there is no mail server (Day 9). The ZIP is ready
anyway: file 1, named after the site ID. In the browser,
“Imports & exports” offers it for download; on the VM you fetch it
directly from the container:
# on argo
cd ~/plausible/ce
docker compose cp plausible:/var/lib/plausible/plausible-exports/1 \
~/plausible/itdrills-export.zip 2>&1 | tail -1
python3 -c "import zipfile, sys
z = zipfile.ZipFile(sys.argv[1])
[print(i.file_size, i.filename) for i in z.infolist()]" \
~/plausible/itdrills-export.zip | head -4
python3 -c "import zipfile, sys
z = zipfile.ZipFile(sys.argv[1])
t = z.read([n for n in z.namelist() if 'imported_pages' in n][0]).decode()
[print(l[:80]) for l in t.splitlines()[:2]]" \
~/plausible/itdrills-export.zipExpected (abridged):
ce-plausible-1 Copied ce-plausible-1:/var/lib/plausible/plausible-exports/1 to …
171 imported_browsers_20261120_20261120.csv
152 imported_custom_events_20261120_20261120.csv
138 imported_custom_props_20261120_20261120.csv
142 imported_devices_20261120_20261120.csv
"date","hostname","page","visits","visitors","pageviews","total_scroll_depth","to
"2026-11-20","itdrills.com","/books/",13,6,17,0,0,0,0
Eleven CSV files with daily totals – no individual events, no visitor IDs. The counterpart is “Import from CSV” in another Plausible instance. (In the lab, importing into a second site was rejected with “Dates Conflict” even though nothing had been imported; for raw data, ClickHouse is the better route anyway, Day 8.)
Save your progress? Sign up for free
Exercise: Speed Drills
- Query the visitors per hour for today through the API. Target time: 60 s
- Count the events per name for today with SQL. Target time: 30 s
Solution
# on argo
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","date_range":"day","metrics":["visitors"],
"dimensions":["time:hour"]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" \
| jq -r '.results[] | "\(.dimensions[0])\t\(.metrics[0])"'
cd ~/plausible/ce
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select name, count() from events_v2 where timestamp >= today()
group by name order by name format TSV"Expected (abridged, values will differ):
2026-11-20 21:00:00 7
2026-11-20 22:00:00 8
Signup 5
engagement 2
pageview 40
signup 1
Save your progress? Sign up for free
Checkpoint
# on argo
stat -c '%a' ~/plausible/api-key
K=$(cat ~/plausible/api-key)
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $K" \
-H 'Content-Type: application/json' https://plausible.lab/api/v2/query \
-d '{"site_id":"itdrills.com","metrics":["visitors"],"date_range":"day"}'
test -s ~/plausible/itdrills-export.zip && echo "Export da"Expected (Export da means “export
present”):
600
200
Export da
Challenge
Which sources do the visitors who sign up come from? Answer it once through the API and once with SQL – the numbers must match.
Hint: In the API the source is called
visit:source; in ClickHouse it is the column
source (on every event of the session).
Solution
# on argo
K=$(cat ~/plausible/api-key)
Q='{"site_id":"itdrills.com","date_range":"day","metrics":["visitors"],
"dimensions":["visit:source"],"filters":[["is","event:goal",["Signup"]]]}'
curl -s -H "Authorization: Bearer $K" -H 'Content-Type: application/json' \
https://plausible.lab/api/v2/query -d "$Q" \
| jq -r '.results[] | "\(.metrics[0])\t\(.dimensions[0])"'
cd ~/plausible/ce
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select uniqExact(user_id), if(source = '', 'Direct / None', source) as q
from events_v2 where name = 'Signup' and timestamp >= today()
group by q order by q format TSV"Expected (values will differ):
4 Direct / None
1 newsletter
4 Direct / None
1 newsletter
An empty source is shown as “Direct / None” in the dashboard – the
if translates it.
Save your progress? Sign up for free
Cleanup
Nothing. The API key and the export stay; on Day 8 the export is part of the backup question.
Interview Note
- How do you get the numbers out of Plausible? Stats API v2
(
POST /api/v2/query) with an API key; with CE, also directly via SQL on ClickHouse. - What do you do without funnels in CE?
windowFunnelin ClickHouse over the stored events. - Is the CSV export a backup? No – daily totals without individual events. Backup means backing up PostgreSQL and ClickHouse (Day 8).
Enterprise Note
- API keys belong to a user – for automation, create a dedicated Plausible user with the “Viewer” role so the key does not depend on one person.
- The API has rate limits; fetch reports once a day and cache them rather than on every page view.
- For a data warehouse: connect ClickHouse read-only (own user, SELECT only) instead of querying the API in loops.
- Without SMTP, export mails, invitations and password resets fail silently in the background – sending mail is part of operations (Day 9).