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
| Name | Required | Description | Default |
|---|---|---|---|
| blockIds | Yes | Array of block IDs to delete in a single batch |
Implementation Reference
- src/tools/batchDeleteBlocks.ts:6-39 (handler)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); } };
- src/tools/blocks.ts:32-33 (registration)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);
- src/schema/blocks.ts:218-222 (schema)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"), };
- src/schema/blocks.ts:304-311 (schema)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), }),
- src/types/blocks.ts:46-47 (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>;