Fix · n8n
Get alerted when an n8n workflow silently stops succeeding
The problem
“When I use the API node to retrieve the primary workflow, I can “workflowPublishHistory” or “active”. Unfortunately, they are both true/activated even if the workflow is in error (red bullet in editor’s view).”
Short answer: Don't ask n8n whether the workflow is on. Ask when it last succeeded. Call GET /api/v1/executions?workflowId=<id>&status=success&limit=1 with the X-N8N-API-KEY header, compare the newest startedAt to your schedule, and alert when it is older than the gap you allow. The internal /rest/workflows/<id>/publication-status route behind the editor dot uses your login session, so an API key gets a 401 there.
A workflow on a 10 minute schedule can stay active for days while every run errors, or while the machine running n8n is asleep. The one signal that catches all of those is "how long since a successful execution". The watchdog checks that, plus the active flag and recent errors, and gives each workflow a verdict: OK, STALE, INACTIVE or ERRORING.
Download
- watchdog.n8n.json: importable n8n workflow (Schedule, Config, three API calls, Verdict, alert, optional reactivate)
- watchdog.py: the same check as a standalone script for cron on another machine
- README.md: full setup notes and limits
- n8n-workflow-health-watchdog.zip: everything, including sample data and the offline test
Step by step
1. Create an API key
In n8n go to Settings, n8n API, and create a key. Then create a Header Auth credential named "n8n API key header" with Name X-N8N-API-KEY and the key as Value. This is the public API. Bearer tokens and the internal /rest routes will not work with it.
2. Test the key from the n8n machine
If this returns 200, the key is fine and any 401 is about how the node sends it.
curl -H "X-N8N-API-KEY: $N8N_API_KEY" http://localhost:5678/api/v1/workflows3. Import the watchdog
Import watchdog.n8n.json. In the Config node, set the base URL, the workflow ids to watch (from each editor URL), maxSilenceMinutes (default 30) and your Slack, Discord or RocketChat incoming webhook URL. Select the credential on the HTTP Request nodes.
4. Understand the three calls
For each workflow id it reads the workflow (active flag), the newest successful execution, and the five newest error executions.
GET {base}/api/v1/workflows/{id}
GET {base}/api/v1/executions?workflowId={id}&status=success&limit=1
GET {base}/api/v1/executions?workflowId={id}&status=error&limit=55. Read the verdict
The Code node computes minutes since the last success. More than maxSilenceMinutes is STALE. Active false is INACTIVE. An error newer than the last success is ERRORING. Anything that is not OK goes to your alert webhook.
6. Optional: turn it back on
Set autoReactivate to true in Config and the watchdog will call POST /api/v1/workflows/{id}/activate for INACTIVE workflows. That only switches it on. It does not fix the cause.
7. Run the watchdog somewhere that stays awake
If n8n runs on a laptop, a watchdog inside the same n8n sleeps with it. Run watchdog.py from cron on a server or another always-on box. It is dry-run by default; --apply sends alerts.
*/30 * * * * N8N_API_KEY=... ALERT_WEBHOOK_URL=... /usr/bin/python3 /path/watchdog.py --base-url https://your-n8n --workflow-id abc123 --apply8. Check it offline first
The zip includes fixtures for a healthy, a stale and an inactive workflow.
python3 watchdog.py --mock sample --workflow-id wf-healthy --workflow-id wf-stale --workflow-id wf-inactive
python3 test_fix.pyWhat this does not cover
- Tested offline against sample responses only, not against a live n8n instance. Check the API docs for your n8n version.
- If your instance does not save successful executions, or prunes them quickly, every workflow will look STALE. Turn on saving successful executions for the watched workflows.
- It does not read trigger activation errors or unpublished draft edits, which the editor dot also shows.
Want this done for you?
Kingdom of Kumar runs it for $500/month, first automation live in 48 hours. Claude + Grok Bot + $500/month (my fee). Email me the task you hate doing every week.