Triggers In Depth
Ch05 Triggers In Depth
Triggers are the entry point of every workflow — they decide when automation runs. n8n provides three trigger categories: scheduled (Schedule), event-based (Webhook/Event), and polling. Choosing the right trigger type directly affects both real-time responsiveness and resource consumption. This chapter covers each type in depth, with special attention to Cron expressions — the foundation of most production scheduled tasks.
Schedule Trigger
Schedule Trigger supports two configuration modes:
Simple mode: Select an interval from a dropdown (every minute, hourly, daily, etc.) — suitable for straightforward recurring tasks.
Cron expression mode: Use Unix Cron syntax for precise scheduling (e.g., "weekdays at 9 AM", "first business day of every month").
Cron Expression Syntax
n8n Cron expressions have 5 fields (no seconds field):
Minute Hour Day Month Weekday
| | | | |
* * * * *
| Field | Range | Special chars |
|---|---|---|
| Minute | 0-59 | * , - / |
| Hour | 0-23 | * , - / |
| Day | 1-31 | * , - / ? |
| Month | 1-12 | * , - / |
| Weekday | 0-7 (both 0 and 7 = Sunday) | * , - / ? |
Common Cron expression examples:
| Expression | Meaning |
|---|---|
0 8 * * * |
Every day at 8:00 AM |
0 8 * * 1-5 |
Weekdays at 8:00 AM |
*/15 * * * * |
Every 15 minutes |
0 9,18 * * * |
Daily at 9:00 AM and 6:00 PM |
0 0 1 * * |
First day of every month at midnight |
30 8 * * 1 |
Every Monday at 8:30 AM |
Timezone: Schedule Trigger uses the n8n instance's system timezone (set via the
GENERIC_TIMEZONEenvironment variable). Always configure the appropriate timezone for your location to prevent triggers firing at unexpected UTC-offset times.
Webhook Trigger: HTTP Event Receiver
Webhook Trigger creates a unique HTTP endpoint URL for your workflow. External systems trigger the workflow by sending HTTP requests to this URL — the core mechanism for real-time, event-driven automation.
Configuration Parameters
- HTTP Method: GET, POST, PUT, PATCH, DELETE (POST recommended)
- Path: Custom URL path, e.g.,
/github-webhook - Authentication: Optional Basic Auth or Header Auth to prevent unauthorized calls
- Response Mode:
Immediately: Returns 200 immediately; workflow executes asynchronouslyWhen Last Node Finishes: Waits for workflow completion, returns last node output (synchronous mode)
Generated webhook URL format:
https://your-n8n.com/webhook/[unique-id-after-activation]
Test URL (while workflow is inactive):
https://your-n8n.com/webhook-test/[unique-id]
Common Webhook Use Cases
- GitHub Webhook: Auto-notify Slack when a PR is merged, or create a Jira ticket
- Form submissions: Website contact form → auto email + write to CRM
- Payment callbacks: Payment success callback → update order status
- AI assistant integration: Feishu bot message → n8n Webhook → LLM → reply
Webhook Security: Signature Verification
For webhooks from GitHub, GitLab, Stripe, etc., verify the request signature to prevent forgery:
// Code node after the Webhook node for signature verification
const crypto = require('crypto');
const secret = $vars.GITHUB_WEBHOOK_SECRET;
const payload = $input.first().json.body;
const signature = $input.first().headers['x-hub-signature-256'];
const expectedSignature = 'sha256=' + crypto
.createHmac('sha256', secret)
.update(JSON.stringify(payload))
.digest('hex');
if (signature !== expectedSignature) {
throw new Error('Invalid webhook signature - request rejected');
}
return $input.all();
Polling Trigger
For services that don't support webhook push, n8n uses periodic polling to check for new data. Many built-in nodes include polling trigger capability:
- Email Trigger (IMAP): Periodically checks inbox; fires when new email arrives
- RSS Feed Trigger: Periodically fetches RSS; fires when new entries appear
- GitHub Trigger: Polls GitHub API; fires on new PR/Issue events
- Google Sheets Trigger: Monitors spreadsheet changes (requires Apps Script)
Polling has lower real-time responsiveness (typically minute-level intervals) and generates frequent API calls. Prefer webhooks over polling whenever the service supports them.
Trigger Selection Guide
| Scenario | Recommended Trigger | Notes |
|---|---|---|
| Scheduled reports, data sync | Schedule Trigger | Most reliable, zero dependencies |
| Receive third-party platform events | Webhook Trigger | Best real-time response |
| Monitor inbox for new emails | Email Trigger | Built-in IMAP polling |
| Monitor RSS content updates | RSS Feed Trigger | Auto-deduplicates read entries |
| Monitor GitHub activity | GitHub Trigger | Supports multiple event types |
| Called by another workflow | Execute Workflow Trigger | Sub-workflow entry point |
Database Trigger (PostgreSQL)
For scenarios requiring immediate triggering when new records are inserted, n8n's PostgreSQL Trigger uses the LISTEN/NOTIFY mechanism for true real-time triggering without polling:
-- Create a trigger function in PostgreSQL
CREATE OR REPLACE FUNCTION notify_new_order()
RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('new_order', row_to_json(NEW)::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Bind the trigger to the orders table
CREATE TRIGGER orders_after_insert
AFTER INSERT ON orders
FOR EACH ROW EXECUTE FUNCTION notify_new_order();
The n8n PostgreSQL Trigger node listens on the new_order channel and fires within milliseconds of each new order insertion — typical latency under 100ms.