bbx
bbx

Reputation: 108

Podio Webhook Verification in Google Apps Script

I have created a Webhook in Podio to my Google Apps Script URL with a doPost function that looks like this:

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("[email protected]", "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("[email protected]", "Data", doPostLogData + "\n\n" + e.parameters.code + "\n\n" + e.parameters.hook_id + "\n\n" + response.getContentText());
}
catch (e) {

GmailApp.sendEmail("[email protected]", "Data", e);
}


return;

}

I am getting the following e-mail (i.e. as a log of what is happening):

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"}

I can't figure out what I'm doing wrong. Someone seemed to ask a similar question here (JSON in Google Apps Script) but I don't think it contained the answer to my question.

Any idea what I'm missing or might be doing wrong? As far as I can tell from Podio's Documentation

Any input is much appreciated. Thank you!

Upvotes: 0

Views: 324

Answers (1)

bbx
bbx

Reputation: 108

To fix the problem I implemented both suggestions from TheMaster and Tanaike. Which were:

  1. Use e.parameter instead.
  2. Remove [] in formData
  3. Modify to 'payload' : JSON.stringify(formData)
  4. Add 'contentType': "application/json" to options.

Upvotes: 1

Related Questions