Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active June 14, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/e587d1921578fe1e808c9b4ce9971776 to your computer and use it in GitHub Desktop.
Save magician11/e587d1921578fe1e808c9b4ce9971776 to your computer and use it in GitHub Desktop.
Verify a FreshBooks webhook
const xml = require('xml');
module.exports = app => {
//processes the webhook for when a new invoice is created
app.post('/webhooks/new-invoice', async (req, res) => {
try {
// debugging
console.log(req.body);
const { name, verifier, object_id } = req.body;
const xmlResponse = xml([
{
request: [
{ _attr: { method: name } },
{ callback: [{ callback_id: object_id }, { verifier }] }
]
}
]);
// debugging
console.log(xmlResponse);
res.set('Content-Type', 'application/xml');
res.send(xmlResponse);
} catch (error) {
res.status(400).send(error);
}
});
};
@magician11
Copy link
Author

Attempting to verify a webhook for FreshBooks from these docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment