I am using Google Forms
, and when I send the answer, I want for the answer to be sent via webhook. Here is my current code:
var POST_URL = "my webhook url";
function onSubmit(e) {
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var response = latestResponse.getItemResponses();
var payload = {};
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle();
var answer = response[i].getResponse();
payload[question] = answer;
}
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
UrlFetchApp.fetch(POST_URL, options);
};
It gives me this error as soon as I run it:
Exception: Request failed for https://WEBHOOK WEBSTIE returned code 400. Truncated server response: {"message": "Cannot send an empty message", "code": 50006} (use muteHttpExceptions option to examine full response)
I .log
ged options
, and it was not empty.
I have little no experience with JS, as I want to use it for webhook only.