joseramoncajide
12/13/2017 - 8:24 AM

klipfolio_slack.gs

var api_key = '';
var datasource_id = '';

function send_to_slack() {

  var url = "https://hooks.slack.com/services/.../.../...";
  
  var payload = {
     "channel" : "#999-pruebas",
     "username" : "robot",
     "text" : "Refrescado datasource",
     "icon_emoji": ":robot_face:", 
     //"icon_url" : "http://image" 
  }
  
  sendToSlack_(url,payload)
}


function sendToSlack_(url,payload) {
   var options =  {
    "method" : "post",
    "contentType" : "application/json",
    "payload" : JSON.stringify(payload)
  };
  return UrlFetchApp.fetch(url, options)
}


function refreshDS() {
 

 var headers = {
 'kf-api-key': api_key,
 'Content-Type': 'application/json'
 };

 var url = 'https://app.klipfolio.com/api/1.0/datasource-instances/'+datasource_id+'/@/refresh';
 var options = {
 'method': 'post',
 'headers': headers,
 };


 var response = UrlFetchApp.fetch(url, options);

 Logger.log(response);
 send_to_slack();
  
}