Clean up archived workflows with the n8n API on a schedule

Go to Workflow
0 views
Built by Alvaro Pérez Alvaro Pérez
Created on July 27, 2026

Description

Quick overview
This workflow runs daily and uses the n8n API to find archived workflows older than a retention threshold, optionally deleting unprotected ones in batches while producing a detailed preview or deletion summary.

How it works
Runs every day at 09:00 (workflow timezone) on a schedule.
Fetches workflows from the n8n API (optionally scoped to a specific project) and keeps only workflows marked as archived.
Validates configuration, then selects deletion candidates based on the retention cutoff date while excluding workflows that include a protected tag.
If dry-run mode is enabled or no candidates exist, outputs a preview-style summary with stats and the candidate list.
If dry-run mode is disabled, splits candidates into individual items and deletes the workflows via the n8n API using configurable batching.
Outputs a final summary including retention settings, candidate details, and deletion success/failure counts.

Setup
Create/select an n8n API credential and assign it to the workflow list and delete actions.
In the config values, set your retention period and keep dry_run enabled until you have reviewed the preview output.
If you plan to enable live deletion (dry_run = false), set project_id to the target n8n project to avoid validation errors.
Set protected_tag to a tag name (for example, "keep") and ensure any workflows you never want deleted are tagged accordingly.
Adjust batch_size and batch_interval_ms to match your instance’s API limits and desired deletion pace.

Nodes Used (1)

Code
n8n-nodes-base.code