I created a chatbot that using Zapier (through Webhook and JSON) for sending to my Google Sheet a name and a phone of user and Apps Script must generate a coupon code automatically. I used function onEdit(e) and it works when I manually enter the text in Google Sheet but when I using the chatbot in not works. Why? What I must change in my script?

This is my script:

var COUPONHERE= [0,2];
var SHEETNAME = 'Main'
function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  if( sheet.getSheetName() == SHEETNAME ) { 
    var selectedCell = ss.getActiveCell();
    if( selectedCell.getColumn() == COLUMNTOCHECK) { 
      var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
      dateTimeCell.setValue(new Date());
      var couponLength = 8;
      var coupon = "";
      var CouponCell = selectedCell.offset(COUPONHERE[0],COUPONHERE[1]);
      for (var i = 0; i 

Because onEdit only is triggered by changes made by the user by using the Google Sheets UI.

Regarding how to make your script work with a Zapier bot or other external programming platform you could use the Google Apps Script API but I think that the details of this is beyond the scope of this site as questions about APIs usually are off-topic on this site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.