API Authentication
All the API calls support authentication with an API key. Redash has two types of API keys:
- User API Key: has the same permissions as the user who owns it. Can be found on your user profile page.
- Query API Key: has access only to the query and its results. Can be found on the query page of a saved query.
Whenever possible we recommend using a Query API key.
The API key can be provided via the Authorization
header, e.g. Authorization: {api_key}
.
1. Use the refresh endpoint to invoke the query
POST /api/queries/<query_id>/refresh
Here’s an example of the response payload:
{ "job": { "status": 1, "error": "", "id": "044bd21a-5cd5-472a-9435-218821ab9537", "query_result_id": null, "updated_at": 0 } }
The job ID (
044bd21a-5cd5-472a-9435-218821ab9537
) will be used for the next step.You can also specify parameters through this api, e.g.:
POST /api/queries/<query_id>/refresh?p_appointment_id=12345
To create a query param in DBX use
{{ param_name }}
within the query and then prefix the param name with p_
in your API calls.
2. Poll the jobs endpoint until the query to completes
GET /api/jobs/<job_id>
Example Response:
{ "job": { "status": 3, "error": "", "id": "044bd21a-5cd5-472a-9435-218821ab9537", "query_result_id": 20952635, "updated_at": 0 } }
Possible statuses:
- 1 == PENDING (waiting to be executed)
- 2 == STARTED (executing)
- 3 == SUCCESS
- 4 == FAILURE
- 5 == CANCELLED
When status is success, the job will include a
query_result_id
which will be used for the next step.
3. Fetch the query result
GET /api/query_results/<query_result_id>
This endpoint will return the response payload.