Google Apps脚本中的Podio Webhook验证

时间:2018-12-19 20:10:37

标签: google-apps-script podio

我已经在Podio中使用如下所示的doPost函数在Google Apps脚本URL中创建了一个Webhook:

function doPost(e) {

  var DecodedPostData = decodeURIComponent(e.postData.contents).replace(/\+/g‌," ");

  doPostLogData = "POST Data Received:\n" + e.postData.contents + "\n\n" + "DECODED POST DATA:\n" + DecodedPostData;

//GmailApp.sendEmail("me@me.com", "Data", "Triggered");

try { 
var response;

      var formData = {   // Make a POST request with file and script data.
            "code": [e.parameters.code]
          }

          var options = {
            'method' : 'post',
            'payload' : formData,
            'muteHttpExceptions' : true
          }

          response = UrlFetchApp.fetch('https://api.podio.com/hook/' + e.parameters.hook_id + '/verify/validate', options);
      GmailApp.sendEmail("me@me.com", "Data", doPostLogData + "\n\n" + e.parameters.code + "\n\n" + e.parameters.hook_id + "\n\n" + response.getContentText());
}
catch (e) {

GmailApp.sendEmail("me@me.com", "Data", e);
}


return;

}

我收到以下电子邮件(即,作为正在发生的事件的日志):

POST Data Received:
hook_id=12345&code=abcde&type=hook.verify

DECODED POST DATA:
hook_id=12345&code=abcde&type=hook.verify

abcde

12345

{"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http:\/\/api.podio.com\/hook\/12345\/verify\/validate","query_string":"","method":"POST"},"error_description":"No
matching operation could be found. No body was
given.","error":"not_found"}

我不知道自己在做什么错。有人似乎在这里问类似的问题(JSON in Google Apps Script),但我认为它不包含我的问题的答案。

知道我丢失了什么或做错了什么吗?据我从Podio's Documentation

所知

非常感谢您的投入。谢谢!

1 个答案:

答案 0 :(得分:0)

为解决此问题,我实施了TheMaster和Tanaike的建议。分别是:

  1. 改为使用e.parameter。
  2. 在formData中删除[]
  3. 修改为“有效载荷”:JSON.stringify(formData)
  4. 在选项中添加“ contentType”:“ application / json”。

谢谢!