Webhooks in Treble allow you to receive real-time notifications about important platform events, such as HSM state changes, session closures, or deployment failures.
The Treble webhook center is where you can configure the URLs of your endpoints to receive real-time notifications about relevant platform events.When an event occurs, Treble sends an HTTP POST request to the URL you configure, including a JSON in the body with the event information. Your server can process this information to execute specific actions such as updating records, sending alerts, or initiating internal processes.
Here’s an example in Node.js to handle a Treble webhook:
Copy
Ask AI
const express = require('express');const app = express();app.use(express.json());app.post('/webhook', (req, res) => { const { event_type } = req.body; console.log('Event received:', event_type); // Process the event according to its type switch (event_type) { case 'hsm.status': // Logic to handle HSM state changes break; case 'session.close': // Logic to handle session closure break; case 'deployment.failure': // Logic to handle deployment failures break; } res.status(200).json({ success: true });});app.listen(3000, () => console.log('Webhook server listening on port 3000'));