Last active
June 14, 2018 18:05
-
-
Save magician11/e587d1921578fe1e808c9b4ce9971776 to your computer and use it in GitHub Desktop.
Verify a FreshBooks webhook
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
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); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Attempting to verify a webhook for FreshBooks from these docs.