Twilio callbacks hit your endpoint, but signature checks fail.
Copy-paste verified examples. Use the tab that matches your stack.
const twilio = require('twilio');
app.post('/webhooks/twilio', (req, res) => {
const authToken = process.env.TWILIO_AUTH_TOKEN;
// CRITICAL: use the exact public URL Twilio sends to
// If behind a proxy, set X-Forwarded-Proto and reconstruct:
const publicUrl = process.env.TWILIO_WEBHOOK_URL;
// e.g. 'https://yourdomain.com/webhooks/twilio'
const isValid = twilio.validateRequest(
authToken,
req.headers['x-twilio-signature'],
publicUrl,
req.body // parsed POST params from express.urlencoded()
);
if (!isValid) {
return res.status(401).type('text/xml').send('<Response><Reject/></Response>');
}
const from = req.body.From;
const body = req.body.Body;
console.log('SMS from', from, ':', body);
// Respond with TwiML
res.type('text/xml').send('<Response><Message>Got it!</Message></Response>');
});Canonical URL check → payload capture → token verification → replay callback.
Works with webhooks and other async event systems (including AI callbacks). Instead of guessing, inspecting the exact payload and headers can help debug faster.
Try the free webhook testerWas this page helpful?
Your feedback helps us improve the docs.