Help us understand the problem. What is going on with this article?

GASにてredash APIを触ってみた

Javascriptを使ってredash API

実行環境はGAS。ライブラリ公開すれば、汎用性が高まるのでおすすめ。
取得したデータをspreadsheetに書き出すと便利。業務で使う場合は、結構おすすめ。

Poll for Fresh Query Results (including parameters)
参考ソース(python)


var httpOptions = {
  method: "",
  headers: {
    Authorization: "",
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }
}

function setApiKey(api_key){
  httpOptions.headers.Authorization = "Key " + api_key
}

// redash refresh query
function getRefreshQuery(redash_url, query_id){
  var refreshUrl = redash_url + '/api/queries/' + query_id + '/refresh'
  httpOptions.method = 'POST'
  var res = UrlFetchApp.fetch(refreshUrl, httpOptions)
  if(res.getResponseCode() !== 200){
    Logger.log('Refresh Failed')
    return 'Refresh Failed'
  }
  return JSON.parse(res)
}

// redash query result
function getQueryResult(redash_url, query_id, result_id){
  var resultUrl = redash_url + '/api/queries/' + query_id + '/results/'+ result_id + '.json'
  httpOptions.method = 'GET'
  var res = UrlFetchApp.fetch(resultUrl, httpOptions)
  var results = JSON.parse(res).query_result.data.rows
  return results
}

// redash check status 
function getQueryJobStatus(redash_url, job_id){
  var jobcheckUrl = redash_url + '/api/jobs/' + job_id
  httpOptions.method = 'GET'
  var res = UrlFetchApp.fetch(jobcheckUrl, httpOptions)
  return JSON.parse(res)
}

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away