How do I create a doPost(e) function in Apps Script project to capture HTTP POST data from web service?

前端 未结 3 768
挽巷
挽巷 2020-12-07 02:53

I\'m trying to create a script to capture data via HTTP POST from Ejunkie. When someone makes a purchase on ejunkie, they can transmit all the order data via HTTP POST to a

相关标签:
3条回答
  • 2020-12-07 02:56

    This is the code I used to post the data to my sheet:

    function doPost(e) {
      Logger.log("I was called")
      if(typeof e !== 'undefined')
      Logger.log(e.parameter);
      var ss= SpreadsheetApp.openById("ID here")
      var sheet = ss.getSheetByName("Sheet2")
      sheet.getRange(1, 1).setValue(JSON.stringify(e))
      return ContentService.createTextOutput(JSON.stringify(e))
    }
    

    Used curl to make a post request and got echo of the data sent!

    0 讨论(0)
  • 2020-12-07 03:00

    Could try something like this? Also you might look @ this thread: doPost(e) does not return parameters but doGet(e) does?

    function doPost(e) {
      
      if(typeof e !== 'undefined')
        return ContentService.createTextOutput(JSON.stringify(e.parameter));
      
    }

    0 讨论(0)
  • 2020-12-07 03:16

    Instead of using Logger.log() as a way to notify yourself if your calls made it through, try sending an email to yourself instead. This is the snippet:

    function doPost(e) {
      if(typeof e !== 'undefined')
    
      MailApp.sendEmail({
         to: "youremail@gmail.com",
         subject: "Call Sucessful",
         htmlBody: "I am your <br>" +
                   "DATA"
        });
    }
    

    Just allow the necessary permission if asked. If I'm not mistaken Logger.log is for script editor only and not for your production web apps.

    0 讨论(0)
提交回复
热议问题