Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
var alreadyStreamed = "Already Streamed";
function stream() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var startRow = sheets[0].getLastRow();
var numRows = 1;
var dataRange = sheets[1].getRange(startRow, 1, numRows, 4);
var streamedRange = sheets[1].getRange("D"+startRow);
var dataValues = dataRange.getValues();
for (var i = 0; i < dataValues.length; ++i) {
var row = dataValues[i];
var timeOrdered = row[0];
var price = row[1];
var deliveryTime = row[2];
};
var url = "https://groker.initialstate.com/api/events?";
var data = [{
"key": "Time Ordered",
"value": timeOrdered},{
"key": "Price",
"value": price},{
"key": "Time to Delivery",
"value": deliveryTime,
}];
var options = {
"method": "post",
"headers": {
"Content-Type":"application/json",
"X-IS-AccessKey":"YOUR_ACCESS_KEY_HERE",
"X-IS-BucketKey":"pietops",
"Accept-Version":"~0",
},
"payload": JSON.stringify(data),
};
if (streamedRange.isBlank()){
var response = UrlFetchApp.fetch(url, options);
response;
sheets[1].getRange(startRow, 4).setValue(alreadyStreamed);
SpreadsheetApp.flush();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment