Webhooks
GoodFit supports syncing company and contact records to your systems via Webhook. This guide will outline the steps to take in order to fully set it up as well as best practices.
Last updated
const signatureHeader = 'x-goodfit-hmac-sha256'
const signatureAlgorithm = 'sha256'
const encodeFormat = 'hex'
const hmacSecret = process.env.WEBHOOK_SECRET
app.post('/webhook', (req, res) => {
// Create digest with payload + hmac secret
const hashPayload = req.rawBody
const hmac = crypto.createHmac(signatureAlgorithm, hmacSecret)
const digest = Buffer.from(signatureAlgorithm + '=' + hmac.update(hashPayload).digest(encodeFormat), 'utf8')
// Get hash sent by the provider
const providerSig = Buffer.from(req.get(signatureHeader) || '', 'utf8')
// Compare digest signature with signature sent by provider
if (providerSig.length !== digest.length || !crypto.timingSafeEqual(digest, providerSig)) {
res.status(401).send('Unauthorized')
}else{
// Webhook Authenticated
// process and respond...
res.json({ message: "Success" })
}
})