Remove and Refresh Database Entries with Notion API

I’m managing a Notion workspace for note-taking and app statistics. How can I remove or modify previous entries with the Notion API? See sample code below.

import { Client as NClient } from '@notionhq/client';
import dotenv from 'dotenv';
dotenv.config();

const notionAPI = new NClient({ auth: process.env.N_TOKEN });
const dbKey = process.env.N_DB_ID;

async function refreshData(record) {
  try {
    await notionAPI.request({
      path: 'pages',
      method: 'POST',
      body: {
        parent: { database_id: dbKey },
        properties: {
          Detail: { title: [{ text: { content: record.detail } }] },
          Category: { rich_text: [{ text: { content: record.cat } }] }
        }
      }
    });
    console.log('Database updated.');
  } catch (error) {
    console.error(error);
  }
}

refreshData({ detail: 'Update version info', cat: 'App' });

I have dealt with this challenge before and discovered that the Notion API does not allow for direct deletion of a database entry. Instead, the recommended approach is to update a specific record to mark it as archived by using the pages.update method. In my project, I modified each record by sending a patch request that set the archived property to true, thereby removing it from active views without actually losing the data. This approach helped maintain a historical log and kept the workspace from becoming cluttered.

Based on personal experience with the Notion API, direct deletion of database pages is not supported. Instead, the common practice involves marking the pages as archived by modifying the archived property through a patch request. This approach retains data integrity by allowing access to historical entries while keeping the active workspace uncluttered. In my implementation, I query existing pages and update their status to archived when they are outdated or need refreshing. This method not only avoids unwanted data loss but also simplifies filtering active entries from those that are no longer needed.

hey jolly, i faced this too. i used a custom staus flag on entries and then filtered them out instead of deletion. it isnt perfect, but it allowed me to keep historical data without hassling with unsupported delete commands.

During development, a similar situation arose when I was tasked with maintaining a large set of note entries within Notion. In my experience, modifying entries rather than deleting them proved to be more efficient. I created a dedicated status field in the database where I would flag items as ‘deprecated’ and used the update method to change this value. This allowed me to maintain an audit trail without physically removing data. The archived approach helped reduce clutter and enabled easy recovery if needed. Additionally, maintaining a historical log can be crucial for compliance and troubleshooting purposes.