How do I run a query with the API?
Run SQL from your own scripts with the Squeezle REST API. Running a query takes three steps: launch a run, poll it until it finishes, then read the results.
-
Create an API token. Open Admin, then API tokens, click New token, name it, and tick the scopes
queries:writeandruns:read. Copy thesqz_...value, because Squeezle shows it only once. -
Launch a run against a connection, and keep the run
idfrom the response. Every endpoint lives under/api/v1on your instance's host.bashBASE=https://your-instance/api/v1 curl -s -X POST "$BASE/runs" \ -H "Authorization: Bearer $SQZ_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"data_source_id":"ds_123","sql":"select id, email from users limit 10","row_limit":100}' -
Poll the run until its
statusreachessuccess:bashcurl -s "$BASE/runs/RUN_ID" -H "Authorization: Bearer $SQZ_TOKEN" -
Read the rows once the run finishes:
bashcurl -s "$BASE/runs/RUN_ID/results" -H "Authorization: Bearer $SQZ_TOKEN"
To run a query you already saved in the app, call POST /queries/{id}/run with
the queries:run scope instead. To download the full result set, call
POST /runs/{id}/exports/{format}.
For the full request bodies, scopes, and a TypeScript example, see the developer guide.