Skip to content

Instantly share code, notes, and snippets.

@clarkbw
Last active December 21, 2016 05:56
Show Gist options
  • Select an option

  • Save clarkbw/c844120085bfac0bb8238d9b4bac1d85 to your computer and use it in GitHub Desktop.

Select an option

Save clarkbw/c844120085bfac0bb8238d9b4bac1d85 to your computer and use it in GitHub Desktop.
re:dash snippet for getting the latest CSV data results from your query
// edit these values
const API_KEY_ID = "9352fd37f2f4ce923932c9c6328829a5be7093ea3d";
const QUERY_ID = 1002;
// leave this
const API_KEY = `?api_key=${API_KEY_ID}`;
const YOUR_REDASH = "https://your.redash.io/api/queries/";
const QUERY_URL = `${YOUR_REDASH}${QUERY_ID}${API_KEY}`;
// XXX: https://crossorigin.me is needed because this request contains no CORS headers
d3.json(`https://crossorigin.me/${QUERY_URL}`, function(error, data) {
// you can remove this console log
console.log('JSON', error, data);
const id = data.latest_query_data_id;
const RESULT_URL = `${YOUR_REDASH}${QUERY_ID}/results/${id}.csv${API_KEY}`;
// you can remove this console log
console.log('url', RESULT_URL);
d3.csv(RESULT_URL, function(data) {
// you can remove this console log
console.log('CSV', data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment