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.

  1. Create an API token. Open Admin, then API tokens, click New token, name it, and tick the scopes queries:write and runs:read. Copy the sqz_... value, because Squeezle shows it only once.

  2. Launch a run against a connection, and keep the run id from the response. Every endpoint lives under /api/v1 on your instance's host.

    bash
    BASE=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}'
  3. Poll the run until its status reaches success:

    bash
    curl -s "$BASE/runs/RUN_ID" -H "Authorization: Bearer $SQZ_TOKEN"
  4. Read the rows once the run finishes:

    bash
    curl -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.