Skip to content

Instantly share code, notes, and snippets.

@ilovefreesw
Created October 20, 2021 04:29
Show Gist options
  • Save ilovefreesw/ef0ad930ffae110804275966e38613d2 to your computer and use it in GitHub Desktop.
Save ilovefreesw/ef0ad930ffae110804275966e38613d2 to your computer and use it in GitHub Desktop.
Google Sheet Webhook Receiver. Recives JSON data posted on the webhook URL. Puts timestamp and JSON data in the Google Sheet.
//this is a function that fires when the webapp receives a GET request
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
var params = JSON.stringify(e.postData.contents);
params = JSON.parse(params);
var myData = JSON.parse(e.postData.contents);
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = Math.max(sheet.getLastRow(),1);
sheet.insertRowAfter(lastRow);
var timeZone = Session.getScriptTimeZone();
var timestamp = date = Utilities.formatDate(new Date(), timeZone, "MM-dd-yyyy | HH:mm:ss");
sheet.getRange(lastRow + 1, 1).setValue(timestamp);
sheet.getRange(lastRow + 1, 2).setValue(params);
SpreadsheetApp.flush();
return HtmlService.createHtmlOutput("post request received");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment