SQL
Save a query
POST
Name, SQL, an optional description and an optional chart type (table, line or bar). The SQL passes the same checks as a run.
AuthorizationBearer <token>
An API token from POST /v2/tokens (at_live_...), or a project's secret key (sk_...) for server-side ingest.
In: header
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v2/queries" \ -H "Content-Type: application/json" \ -d '{ "name": "Signups", "sql": "select count(*) from events where name = \'signup\'" }'{ "data": { "id": "sq_6f1c2a4e-8b3d-4c5e-9f70-a1b2c3d4e5f6", "name": "Top routes this week", "sql": "select route, count(*) as views from pageviews where is_human and ts >= :from group by 1 order by 2 desc limit 10", "description": "For the weekly check-in", "chart": "bar", "createdBy": { "kind": "user", "id": "user_remco" }, "createdAt": "2026-09-27T16:40:00.000Z", "updatedAt": "2026-09-27T16:40:00.000Z" }}