Webhook-Triggered Automations
Create automations that respond to external webhook events in real-time.
What You'll Build
In this tutorial, you'll learn how to:
- Create automations triggered by webhooks
- Configure webhook endpoints and security
- Process incoming webhook data
- Verify webhook signatures for security
- Handle different webhook payload formats
Prerequisites
Before You Start
- ✅ A Sematryx account with an active API key
- ✅ Understanding of HTTP webhooks
- ✅ Ability to send HTTP POST requests (curl, Postman, or similar)
Step 1: Create Webhook Automation
Create an automation with a webhook trigger:
curl -X POST https://api.sematryx.com/v1/automations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "webhook-processor",
"trigger": {
"type": "webhook",
"config": {
"path": "/webhook/process",
"method": "POST"
}
},
"actions": [
{
"type": "log",
"config": {
"message": "Received webhook: {{trigger.body}}"
}
},
{
"type": "transform",
"config": {
"input_format": "json",
"output_format": "json"
}
}
]
}'After creation, you'll receive a webhook URL that you can use to trigger the automation.
Step 2: Get Your Webhook URL
Retrieve the webhook URL from the automation response:
https://api.sematryx.com/webhook/process?token=YOUR_WEBHOOK_TOKENSecurity Note
The webhook token is unique to your automation and should be kept secret. Anyone with the token can trigger your automation.
Step 3: Trigger the Webhook
Send a POST request to your webhook URL:
curl -X POST https://api.sematryx.com/webhook/process?token=YOUR_WEBHOOK_TOKEN \
-H "Content-Type: application/json" \
-d '{
"event": "user_signup",
"user_id": "user_123",
"email": "user@example.com",
"timestamp": "2024-01-01T00:00:00Z"
}'The automation will process the webhook payload and execute its actions.
Step 4: Using the Python SDK
You can also create and manage webhook automations using the Python SDK:
from sematryx import SematryxClient
client = SematryxClient(api_key='your-api-key')
# Create webhook-triggered automation
automation = client.automations.create(
name='webhook-processor',
trigger={
'type': 'webhook',
'config': {
'path': '/webhook/process',
'method': 'POST'
}
},
actions=[
{
'type': 'log',
'config': {
'message': 'Received webhook'
}
}
]
)
print(f'Webhook URL: {automation.trigger.webhook_url}')Step 5: Webhook Security
For production use, always verify webhook signatures:
import hmac
import hashlib
def verify_webhook_signature(payload, signature, secret):
expected = hmac.new(
secret.encode(),
payload.encode(),
hashlib.sha256
).hexdigest()
return hmac.compare_digest(signature, expected)Security Best Practices
- Always verify webhook signatures
- Use HTTPS for webhook URLs
- Rotate webhook tokens regularly
- Implement rate limiting on webhook endpoints
- Log all webhook requests for auditing
Common Use Cases
Event Processing
Process events from external systems like payment processors, CRM systems, or analytics platforms.
Data Synchronization
Keep data in sync between different systems when changes occur.
Notifications
Trigger notifications or alerts based on external events.
Workflow Automation
Automate business workflows that span multiple systems.
🎉 Next Steps
You've learned how to create webhook-triggered automations! Continue learning: