Greetings!
I am building one app script to fetch the payload from Panda and put it to Google Sheet.
So the scenario is:
Document created/updated in pandoc > Webhook triggered and it will send data to Google Sheet based on logic in App script.
I have created a webapp and dopost function to fetch the payload but i dont know how to run it because manually running gives an error as dopost function is not defined.
This is script I am trying to run:
function doPost(e) {
// Check if postData is present
if (!e.postData || !e.postData.contents) {
return ContentService.createTextOutput('No payload received.');
}
const payload = JSON.parse(e.postData.contents);
// Log the payload
Logger.log(JSON.stringify(payload, null, 2));
// Add the payload to the sheet
appendPayloadToSheet(payload);
// Return the payload as text output
return ContentService.createTextOutput(JSON.stringify(payload, null, 2)).setMimeType(ContentService.MimeType.JSON);
}
/**
* Append the payload data to the Google Sheet
*/
function appendPayloadToSheet(payload) {
const spreadsheetId = ''; // Replace with your Google Sheets ID
const sheetName = ''; // Replace with your sheet name
const sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
// Extract data from payload
const event = payload.event;
const data = payload.data;
const id = data.id;
const name = data.name;
const dateCreated = data.date_created;
const dateModified = data.date_modified;
const status = data.status;
const recipientEmail = data.recipients[0].email;
// Append the data to the sheet
sheet.appendRow([event, id, name, dateCreated, dateModified, status, recipientEmail]);
}
I have tried to deploy it and run it but the manually running gives an error as “event not defined”.
Dhruvin Sheth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.