0

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 COLUMNTOCHECK = 2;
var DATETIMELOCATION = [0,1];
var COUPONHERE= [0,2];
var SHEETNAME = 'Main'
var COUPON_CHARS_RANGE = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
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 
0

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.

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