Created
July 28, 2020 10:47
-
-
Save ozgurshn/5dcf632f1f85a90e572593354ebfe08a to your computer and use it in GitHub Desktop.
Add new row with post request to Google Sheet using Google App Script
This file contains hidden or 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
const doPost = (request = {}) => { | |
try{ | |
var sheetApp = SpreadsheetApp.openByUrl("YoursharedSheetLINK"); | |
var sheet = sheetApp.getSheets()[0]; | |
const { parameter, postData: { contents, type } = {} } = request; | |
const { source } = parameter; | |
if (type === 'application/json') { | |
const jsonData = JSON.parse(contents); | |
var textdata = JSON.stringify(jsonData) | |
sheet.appendRow([textdata]) | |
} | |
return ContentService | |
.createTextOutput(JSON.stringify({"result":"success"})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} catch(e){ | |
// if error return this | |
return ContentService | |
.createTextOutput(JSON.stringify({"result":"error", "error": e})) | |
.setMimeType(ContentService.MimeType.JSON); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment