POST /api/sites/{id}/query runs a read-only SQL query against your site’s analytics data and returns rows with typed column metadata — the programmatic form of the SQL query builder. You write a SELECT against virtual tables that are already scoped to your site.
The scoped tables
All three are automatically filtered to the site in the URL — you never write a
site_id filter, and a query cannot reach another site’s data.
scoped_stripe_revenue is append-only. Deduplicate Stripe webhook replays by stripe_event_id before aggregating:
Response
columns preserves order and gives each column’s type, so you can render results without inferring shapes.
Limits
The query runs read-only, so it can never modify your data:- A single
SELECT(orWITH … SELECT) reading the scoped tables and your own CTEs — writes, schema changes, multiple statements, and reads outside the scoped tables are rejected. - A query runs for at most 10 seconds and returns at most 1,000 rows.
400 with the database’s message so you can fix the query.
Frequently asked questions
Can a query reach another site's data?
Can a query reach another site's data?
No. All three scoped tables are automatically filtered to the site in the URL of
POST /api/sites/{id}/query. You never write a site_id filter, and a query cannot reach another site’s data.How many rows can a scoped SQL query return?
How many rows can a scoped SQL query return?
At most 1,000 rows, and the query runs for at most 10 seconds. Both limits apply to every call to
POST /api/sites/{id}/query.What happens if my SQL is invalid?
What happens if my SQL is invalid?
The endpoint returns a
400 with the database’s own error message, so you can fix the query. Writes, schema changes, multiple statements, and reads outside the scoped tables are rejected the same way — the query runs read-only and can never modify your data.Related
SQL query builder
The same capability, in the dashboard.
Analytics read API
Fixed reports when you don’t need raw SQL.
Custom dashboards
Turn a query into a saved chart.
Metric definitions
The events and columns you can query.