Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
//Return if null
if( e == undefined ) {
Logger.log("no data");
return HtmlService.createHtmlOutput("need data");
//Parse the JSON data
var event = JSON.parse(e.postData.contents);
var data = JSON.parse(;
//Get the last row without data
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = Math.max(sheet.getLastRow(),1);
//Get current timestamp
var timestamp = new Date();
//Insert the data into the sheet
sheet.getRange(lastRow + 1, 1).setValue(event.published_at);
sheet.getRange(lastRow + 1, 2).setValue(data.temperature);
sheet.getRange(lastRow + 1, 3).setValue(data.humidity);
sheet.getRange(lastRow + 1, 4).setValue(data.pm10);
sheet.getRange(lastRow + 1, 5).setValue(data.pm25);
sheet.getRange(lastRow + 1, 6).setValue(data.tvoc);
sheet.getRange(lastRow + 1, 7).setValue(data.c02);
return HtmlService.createHtmlOutput("post request received");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment