Automate Notion Duplicate Cleanup with n8n Workflow

Struggling with duplicate entries clogging your Notion database? This n8n workflow identifies and archives duplicate pages automatically based on a chosen property, saving you hours of manual cleanup.
notion
scheduleTrigger
code
+2
Workflow Identifier: 1872
NODES in Use: Schedule Trigger, Notion, Aggregate, Set, Code
Automate Notion cleanup with n8n

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Automation Does

This workflow finds duplicate pages in a Notion database using a property you choose.

It then archives the extra copies, so your database stays clean.

The workflow runs automatically daily or when a new page is added.

This saves time and avoids mistakes of deleting wrong pages.


Tools and Services Used

  • Notion API: Allows access to database pages and archive actions.
  • n8n Automation Tool: Runs workflow with nodes like Get pages from database and Code node.
  • JavaScript: Used in Code node to find duplicates by property.

Workflow Inputs, Processing, and Outputs

Inputs

  • Notion database ID of the target database.
  • User-selected property for duplicate detection (like Task Name or Email).
  • API Key for Notion to allow read and write actions.

Processing Steps

  • Get pages from database node collects all pages from Notion.
  • Set node formats the pages to include the chosen property to check.
  • Aggregate node bundles all pages into an array for easier processing.
  • Code node runs JavaScript to spot duplicates by checking repeated property values.
  • Archive pages node archives all extra duplicate pages to clean the database safely.

Outputs

  • Duplicated pages are archived (hidden but recoverable) in Notion.
  • One copy of each unique page remains in the database.
  • The database becomes clearer and easier to manage.

Beginner Step-by-Step: How to Use This Workflow in n8n

Step 1: Download and Import

  1. Download the workflow file using the Download button on this page.
  2. Open the n8n editor and choose Import from File to load the workflow.

Step 2: Configure Credentials

  1. Add or update the Notion API Key in the Credentials section.

Step 3: Update IDs and Properties

  1. In the Get pages from database node, enter your Notion database ID from the URL.
  2. In the Set node, assign the property to check for duplicates using drag-and-drop from incoming data.

Step 4: Test the Workflow

  1. Run the workflow manually once to check it finds and archives duplicates correctly.

Step 5: Activate for Production

  1. Turn on the desired trigger: daily schedule or when a new page is added.
  2. Save and activate the workflow to run automatically.

Note: For self hosting n8n, this workflow works fine on any server. See self-host n8n for help.


Understanding the Duplicate Detection Code

The Code node uses this JavaScript to find duplicates:

const inputData = $input.first().json.pages;

const seen = new Set();
const duplicates = new Map();

inputData.forEach(item => {
  const propertyValue = item.property_to_check;
  if (seen.has(propertyValue)) {
    duplicates.set(propertyValue, item);
  } else {
    seen.add(propertyValue);
  }
});

const output = Array.from(duplicates.values()).map(item => ({ json: item }));

return output;

This script looks through all pages and remembers property values seen.

If a property value shows again, it marks the page as duplicate.

It returns only pages duplicated after the first.


Customization Ideas

  • Change the property to check in the Set node.
  • Adjust the schedule trigger to run more or less often.
  • Switch the Archive pages node to delete pages permanently if desired.
  • Add notification nodes like Slack or email for alerts on archived pages.
  • Clone the workflow to manage multiple Notion databases.

Troubleshooting

No pages returned from Notion

Check the database ID is correct and your Notion API Key has the right permissions.

Duplicate detection not working

Confirm the property used to find duplicates is correct and properly selected in the Set node.

Workflow fails to archive pages

Verify API permissions and token validity.

Try splitting large batches or add timing delays if hitting rate limits.


Pre-Production Checklist

  • Verify the Notion API Key is active and authorized.
  • Run the workflow manually before turning on triggers.
  • Check the property_to_check field matches the duplicate criteria.
  • Test on non-important data to avoid accidental data loss.
  • Backup Notion data before running at scale.

Deployment Guide

Activate the workflow by switching on the triggers in n8n.

Use either daily schedule or new page created to run automatically.

Monitor logs to catch any errors or confirmations of archived pages.

Review archives regularly and adjust settings as your database changes.


Summary

✓ Automatically finds duplicate pages using a chosen property.

✓ Archives duplicates safely to keep Notion database clean.

✓ Saves time by removing manual checking and deleting tasks.

→ Keeps project management data organized and easier to use.

Automate Notion cleanup with n8n

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The workflow currently works with one property. To use multiple, edit the JavaScript code in the Code node to check several property values combined.
Archiving hides pages but does not delete them permanently. Archived pages can be restored later if needed.
Yes, the workflow can be cloned for each database and the database ID must be updated accordingly.
Check that the correct database ID is used and that the Notion API credentials have read access to the database.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.