0

I'm trying to get POST request in Gsheet using Apps Script (as a Webapp)! It works well for JavaScript body POST type but when I tried with x-www-form-urlencoded there is an error.

function doPost(e) {

//Return if null
  if( e == undefined ) {
      console.log("no data");
      return HtmlService.createHtmlOutput("need data");
    }

//Parse the JSON data

  var event = JSON.parse(e.postData.contents);
  var data = event.data;


//Get the last row without data

  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow = Math.max(sheet.getLastRow(),1);
  sheet.insertRowAfter(lastRow);

//Get current timestamp

  var timestamp = new Date();

//Insert the data into the sheet

  sheet.getRange(lastRow + 1, 1).setValue(event.bt_signature);
  sheet.getRange(lastRow + 1, 2).setValue(data.bt_payload);
  SpreadsheetApp.flush();

  return HtmlService.createHtmlOutput("post request received");}

Thanks!

  • Does this answer your question? [application/x-www-form-urlencoded or multipart/form-data?](https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data) – Cooper Jan 30 '20 at 20:47

1 Answers1

2

For x-www-form-urlencoded content, POST data is stored in the parameter and parameters properties of the event object. See documentation.

TheAddonDepot
  • 8,408
  • 2
  • 20
  • 30