Last active
November 17, 2019 00:39
-
-
Save bmcbride/0c32edf4fb96bb5801b7 to your computer and use it in GitHub Desktop.
Simple Google Apps Script, which can be used as a Fulcrum webhook endpoint to email the webhook JSON payload for debugging. Required URL parameter: email. Optional URL parameter: form (Fulcrum form_id).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e){ | |
return handleResponse(e); | |
} | |
function handleResponse(e) { | |
var email = e.parameter.email; | |
var form = e.parameter.form; | |
var jsonString = e.postData.getDataAsString(); | |
var payload = JSON.parse(jsonString); | |
var subject = "Fulcrum Webhook Payload"; | |
if (form && form.length) { | |
if (payload.data.form_id === form) { | |
if (payload.type === "record.create") { | |
subject = "New Fulcrum record created"; | |
sendMail(); | |
} else if (payload.type === "record.update") { | |
subject = "Fulcrum record updated"; | |
sendMail(); | |
} else if (payload.type === "record.delete") { | |
subject = "Fulcrum record deleted"; | |
sendMail(); | |
} | |
} | |
} else { | |
sendMail(); | |
} | |
function sendMail() { | |
MailApp.sendEmail({ | |
to: email, | |
name: "Fulcrum Webhook", | |
subject: subject, | |
htmlBody: jsonString | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment