Overview
Webhooks in Directus are implemented through the Flows system using webhook triggers. This provides a powerful way to create custom API endpoints that execute automated workflows.Webhooks in Directus are part of the Flows automation system. For more details on flows, see Flows & Automation.
Creating Webhook Flows
A webhook flow consists of a trigger and operations:Webhook Trigger Options
HTTP Method
Specify which HTTP method triggers the flow:Async Execution
Control whether the webhook waits for completion:- async: false - HTTP request waits for flow completion, returns result
- async: true - Returns immediately, flow executes in background
Return Value
Specify what data to return in the HTTP response:Webhook URL
Once created, webhook flows are accessible at:Accessing Webhook Data
Webhook payload is available in operations via$trigger:
Webhook Context
Additional context available:{{$trigger.body}}- Request body (JSON){{$trigger.query}}- Query parameters{{$trigger.headers}}- HTTP headers{{$accountability.user}}- Authenticated user (if token provided){{$accountability.role}}- User’s role{{$accountability.ip}}- Request IP address
Authentication
Webhooks can be authenticated using access tokens:Public Webhooks
To create a public webhook (no authentication required):- Create the flow with webhook trigger
- Set permissions for the Public role
- Allow access to the flow
Example Workflows
Simple Data Ingestion
Receive data from external service:Conditional Processing
Process different data types:External API Integration
Receive webhook, process, and call external API:Validation and Error Handling
Validate input and handle errors:GET Webhooks with Caching
For GET webhooks, enable caching:Response Format
Successful Response
Error Response
Query Parameters
Access query parameters in operations:Headers
Access request headers:Rate Limiting
Implement rate limiting for webhooks:Webhook Logs
Log all webhook calls for debugging:Best Practices
Validate Input
Validate Input
Always validate webhook input using condition operations before processing data.
Use Async for Long Operations
Use Async for Long Operations
Set
async: true for webhooks that trigger long-running operations to avoid timeouts.Implement Authentication
Implement Authentication
Use Bearer tokens or API keys to secure webhooks. Don’t rely on obscurity alone.
Log Webhook Calls
Log Webhook Calls
Keep logs of webhook calls for debugging and audit purposes.
Handle Errors Gracefully
Handle Errors Gracefully
Use condition operations to detect errors and return appropriate error messages.
Rate Limit Public Webhooks
Rate Limit Public Webhooks
Implement rate limiting to prevent abuse of public webhook endpoints.