Receiving Inbound Webhooks
This is only relevant if you are self-hosting Sombra™{' '} and using our Preference Management product!
This guide explains how to set up a webhook receiver that securely forwards incoming requests to your locally hosted Sombra cluster instance. The receiver will transform incoming requests into a standardized PUT request to the /v1/preferences endpoint with proper authentication.
When you need to receive webhooks from external vendors and forward them to Sombra, you'll need to:
- Set up a webhook receiver endpoint that's accessible to external services
- Transform incoming requests into the expected Sombra format. The API is documented here.
- Add proper authentication headers
- Forward the request to your Sombra cluster
Here's a high-level example of how to implement this using Node.js and Express:
JavaScript
const express = require('express');
const axios = require('axios');
const app = express();
// Your Sombra configuration
const SOMBRA_URL = 'http://localhost:5040'; // Make sure this points to your internal Sombra (customer-ingress)
const INTERNAL_KEY = process.env.INTERNAL_KEY;
const TRANSCEND_API_KEY = process.env.TRANSCEND_API_KEY;
app.put('/v1/preferences', express.json(), async (req, res) => {
try {
// You may wish to transform the payload before forwarding to Sombra,
// But usually it is possible to setup the webhook in the external vendor
// such that it conforms to our API format.
await axios.put(`${SOMBRA_URL}/v1/preferences`, req.body, {
headers: {
Authorization: `Bearer ${TRANSCEND_API_KEY}`,
'x-sombra-authorization': `Bearer ${INTERNAL_KEY}`,
'Content-Type': 'application/json',
},
});
res.status(200).json({ success: true });
} catch (error) {
console.error('Error forwarding webhook:', error);
res.status(500).json({ error: 'Failed to process webhook' });
}
});
app.listen(3001, () => {
console.log('Webhook receiver listening on port 3001');
});- Authentication: Ensure your webhook receiver endpoint is secured with appropriate authentication mechanisms (e.g., API keys, HMAC signatures).
- Input Validation: Validate all incoming webhook data before forwarding to Sombra.
- Rate Limiting: Implement rate limiting to prevent abuse of your webhook endpoint.
- HTTPS: Always use HTTPS for your webhook receiver endpoint.
- Error Handling: Implement proper error handling and logging for failed webhook deliveries.
The following environment variables should be configured:
SOMBRA_URL: The URL of your Sombra cluster. Make sure this is for your "Customer Ingress" Sombra endpoint.TRANSCEND_API_KEY: The Transcend API Key. You can create one by navigating to Admin Dashboard > Infrastructure. The API key needs the following scopes:- Modify User Stored Preferences
- View Managed Consent Database Admin API
- View Preference Store Settings
INTERNAL_KEY: The Sombra API key. The hash of this key is stored in theINTERNAL_KEY_HASHenvironment variable on Sombra.
To test your webhook receiver:
- Start your webhook receiver service
- Use a tool like cURL or Postman to send test webhooks to your endpoint
- Monitor the logs to ensure proper forwarding to Sombra
- Verify that the data appears correctly in your Sombra cluster
- Idempotency: Implement idempotency checks to handle duplicate webhook deliveries.
- Retries: Implement a retry mechanism for failed forwards to Sombra.
- Monitoring: Set up monitoring and alerting for your webhook receiver.
- Documentation: Document the expected webhook payload format and any specific requirements for your implementation.
- Versioning: Consider implementing versioning for your webhook endpoints to handle future changes gracefully.