Here’s my App Script for the guestbook, it’s not the best written thing ever but it works. If you use this or a modified version of it, let me know!

function trunc(text, maxLen) {
  if (text.length > maxLen) {
    return text.slice(0, maxLen);
  }
  return text;
}

function doPost(data) {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  const date = new Date();
  const row = [
    `${date.toDateString()} ${date.toTimeString().split("GMT")[0]} CST`,
    trunc(data.parameter.name,64),
    trunc(data.parameter.message,600),
  ];

  sheet.appendRow(row);

  return ContentService
    .createTextOutput(JSON.stringify({'message':'Submitted!'}))
    .setMimeType(ContentService.MimeType.JSON);
}

function doGet() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues();

  const headers = data.shift();
  const jsonData = data.map(row => {
    let obj = {};
    headers.forEach((header, index) => {
      obj[header] = row[index]
    });
    return obj
  });

  jsonData.reverse();

  const response = ContentService
    .createTextOutput(JSON.stringify(jsonData))
    .setMimeType(ContentService.MimeType.JSON);
  return response;
}

Back