What is the best way to programatticaly export a CSV from a SQL query output?

Context:
We pipe all our production metrics into a SQL DB accessbile via Redash. Our customer support team wants to take the output of one of their SQL queries and push it to another dashboard tool they’re using. This particular tool doesn’t have a typical REST API importer, instead they suck in CSVs off of a shared S3 bucket.

So I need to figure out a way to programatticaly export a CSV from a SQL query in Redash. This way the customer support team can modify the query as they wish to change what gets imported into their tool.

Is there a way to trigger the CSV export functionality via an API call to Redash? IE, curl an endpoint and get the CSV back?

You can access every query’s results via the API: GET /api/qeuries/{id}/results.csv
One thing to note that this will give you the last cached result, which might be outdated. If you want to make sure you always get the latest result before putting it in S3, you can use the refresh API:

POST /api/queries/{id}/refresh, this will trigger a query refresh and return a job id you can poll to know when the result is ready. For both APIs you can either use a user API key or a query API key.

1 Like

Hi. is there a way to refresh a query with different filters, that we define in redash with {{}}

Yes, see this Gist for an example:

Dears ,
How can i connect R to Redash to update Queries and automatically download data as CSV please ??

I get a 404 Not found when I use the trigger POST /api/queries/{id}/refresh, with no parameter