Skip to main content

Hi all,

I have a zap that takes the output from a Cognito form submission and ports it over to a Google sheet. I also would like to run a webhook that, after the sheet is updated, triggers a doPost() script to update one cell in the row that was just added based on a lookup to another tab of the sheet. The script works correctly - I have tested it with a helper script and it ran fine through the Google apps script debugger - but it will not run correctly when in the zap workflow.

Here is the code of the doPost script:

function doPost(e) {
try {
// Parse the incoming POST data
var data = JSON.parse(e.postData.contents);

var sheetName = data.sheetName;
var editedRow = data.row;
var studentID = data.studentID;

// Log the incoming data for debugging
Logger.log("Received data: " + JSON.stringify(data));
Logger.log("Sheet name: " + sheetName);
Logger.log("Row: " + editedRow);
Logger.log("Student ID: " + studentID);

// Open the spreadsheet and find the target sheet by name
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);

if (!sheet) {
Logger.log("Error: Sheet not found - " + sheetName);
return ContentService.createTextOutput("Sheet not found").setMimeType(ContentService.MimeType.TEXT);
}

// Validate row number
if (editedRow < 1 || editedRow > sheet.getMaxRows()) {
Logger.log("Error: Invalid row number - " + editedRow);
return ContentService.createTextOutput("Invalid row number").setMimeType(ContentService.MimeType.TEXT);
}

// Proceed with modifying data
var statusCell = sheet.getRange(editedRow, 16); // Column P (16th column) for status

var currentStatus = statusCell.getValue();
if (currentStatus === "") {
statusCell.setValue("Processed"); // Change to whatever value you want
Logger.log("Student " + studentID + " processed and status updated.");
}

var response = ContentService.createTextOutput("Processed successfully");
response.setMimeType(ContentService.MimeType.TEXT);

return response;

} catch (err) {
Logger.log("Error processing POST request: " + err.message);
return ContentService.createTextOutput("Error: " + err.message).setMimeType(ContentService.MimeType.TEXT);
}
}

// Function to get the student status from enrollments sheet
function getStudentStatus(studentID, enrollmentsSheet) {
var enrollmentsData = enrollmentsSheet.getDataRange().getValues();

// Loop through the "2024-25 Enrollments" sheet to find the student ID and return the status
for (var i = 1; i < enrollmentsData.length; i++) {
if (enrollmentsData[i][4] === studentID) { // Student ID is in column E (5th column)
return enrollmentsData[i][15]; // Return the status (New or Returning) from column P (16th column)
}
}

// If no match is found in the 2024-25 sheet, search in the "2025-26 Enrollments" sheet
var enrollmentsSheet2025 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("2025-26 enrollments");
var enrollmentsData2025 = enrollmentsSheet2025.getDataRange().getValues();

// Loop through the "2025-26 Enrollments" sheet to find the student ID and return the status
for (var i = 1; i < enrollmentsData2025.length; i++) {
if (enrollmentsData2025[i][4] === studentID) { // Student ID is in column E (5th column)
return enrollmentsData2025[i][15]; // Return the status (New or Returning) from column P (16th column)
}
}

// If no match is found in either sheet, return "New"
return "New";
}

 

The webhook options I am using are:

  • Method: POST
  • URL is correct (I have tested it and it runs correctly)
  • Data:
    • {
        "sheetName": hard-coded tab name
        "row": row number from the Create Spreadsheet Row task in the zap,
        "studentID": Student ID number as entered in the Cognito form that is passed into the zap to begin the automation
      }
  • Unflatten: yes
  • Basic Auth: blank
  • Headers:
    • Content-Type: application/json

When the webhook runs, the only thing that returns in the zap is “Processed successfully”. None of the other information that is supposed to run through the logger gets to the Data out area of the zap.

What am I missing here? Is it a coding thing or do I not have the webhook set up correctly?

Thank you!

Be the first to reply!

Reply