Setting Up Flows (Automation) in Directus
Flows are a visual automation builder in Directus. Logic: trigger (event) → chain of operations. Without coding, you can set up notifications, data synchronization, API calls, email sending.
Flow Triggers
- Event Hook — collection event (create, update, delete)
- Schedule — by schedule (cron)
- Webhook — incoming HTTP request
- Manual — manual run from admin UI
- Another Flow — call from another Flow
Example: Notification on New Order
Trigger: Event Hook → items.create → collection orders
Operations:
-
Read Data — get order details with populate
{ "collection": "orders", "key": "{{$trigger.key}}", "query": { "fields": ["*", "customer.*"] } } -
Condition — check that order is expensive
{ "rule": { "total": { "_gte": 10000 } } } -
Send Email (via Operations → Email)
To: [email protected] Subject: Large order #{{$last.id}} for {{$last.total}} $ Body: Customer: {{$last.customer.email}} -
Webhook → POST to Slack
{ "url": "{{SLACK_WEBHOOK}}", "method": "POST", "body": { "text": "New order #{{$last.id}} from {{$last.customer.email}}" } }
Example: Daily Report (Schedule)
Trigger: Schedule → 0 9 * * 1-5 (at 9:00 AM, Mon-Fri)
Operations:
-
Read Data — last 24 hours of orders
{ "collection": "orders", "query": { "filter": { "date_created": { "_gte": "$NOW(-24h)" }, "status": { "_in": ["paid", "delivered"] } } } } -
Transform (JS code)
const orders = $last const total = orders.reduce((sum, o) => sum + o.total, 0) return { count: orders.length, revenue: total } -
Webhook → Slack with summary
Example: Incoming Webhook (Stripe)
Trigger: Webhook → POST method
Operations:
-
Condition — check event type
{ "rule": { "type": { "_eq": "checkout.session.completed" } } } -
Read Data — find order by ID from metadata
{ "collection": "orders", "query": { "filter": { "stripe_session_id": { "_eq": "{{$trigger.body.data.object.id}}" } } } } -
Update Data — update order status
{ "collection": "orders", "key": "{{$last[0].id}}", "payload": { "status": "paid" } }
Custom Operation Extension
For operations not in the standard set:
// extensions/operations/send-sms/index.ts
export default {
id: 'operation-send-sms',
handler: async ({ phone, message }: { phone: string; message: string }) => {
const response = await fetch('https://api.sms.ru/sms/send', {
method: 'POST',
body: new URLSearchParams({
api_id: process.env.SMSRU_API_ID!,
to: phone,
msg: message,
}),
})
return response.json()
},
}
Environment Variables in Flows
In Directus settings (Settings → Project Settings → Flows Variables) you can set variables available to all Flows:
SLACK_WEBHOOK = https://hooks.slack.com/...
CRM_API_URL = https://api.crm.com
In operation reference as {{SLACK_WEBHOOK}}.
Debugging Flows
Directus saves execution logs for each Flow — in admin you can see each step with input/output data and errors. "Test" button allows manual run with mock data.
Timeline
Setting up 3–5 Flows (notifications, webhooks, reports) — 1–2 days without coding.







