Created
October 20, 2021 04:29
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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