Skip to main content
Glama

batch_delete_blocks

Remove multiple blocks at once by specifying their IDs, streamlining content cleanup and management in Notion.

Instructions

Delete multiple blocks in a single operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockIdsYesArray of block IDs to delete in a single batch

Implementation Reference

  • The core handler function `batchDeleteBlocks` that loops through an array of block IDs and deletes each block using the Notion API's blocks.delete method. It collects results and returns a formatted response indicating success or handles errors.
    export const batchDeleteBlocks = async ( params: BatchDeleteBlocksParams ): Promise<CallToolResult> => { try { const results = []; for (const blockId of params.blockIds) { const response = await notion.blocks.delete({ block_id: blockId, }); results.push({ blockId, success: true, response, }); } return { content: [ { type: "text", text: `Successfully deleted ${params.blockIds.length} blocks (moved to trash)`, }, { type: "text", text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { return handleNotionError(error); } };
  • Within the main `registerBlocksOperationTool` dispatcher, the case for action 'batch_delete_blocks' invokes the specific batchDeleteBlocks handler.
    case "batch_delete_blocks": return batchDeleteBlocks(params.payload.params);
  • Zod schema defining the input parameters for batch_delete_blocks: an array of block ID strings.
    export const BATCH_DELETE_BLOCKS_SCHEMA = { blockIds: z .array(z.string().describe("The ID of a block to delete/archive")) .describe("Array of block IDs to delete in a single batch"), };
  • Part of the BLOCKS_OPERATION_SCHEMA discriminated union, defining the 'batch_delete_blocks' action with its literal value and associated params schema.
    z.object({ action: z .literal("batch_delete_blocks") .describe( "Use this action to perform batch delete operations on blocks." ), params: z.object(BATCH_DELETE_BLOCKS_SCHEMA), }),
  • Exports the full Zod schema object and infers the TypeScript type for BatchDeleteBlocksParams.
    export const batchDeleteBlocksSchema = z.object(BATCH_DELETE_BLOCKS_SCHEMA); export type BatchDeleteBlocksParams = z.infer<typeof batchDeleteBlocksSchema>;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/awkoy/notion-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server