batch_update_blocks
Update multiple Notion blocks simultaneously by specifying an array of operations, streamlining bulk modifications for improved workflow efficiency.
Instructions
Update multiple blocks in a single operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operations | Yes | Array of update operations to perform in a single batch |
Implementation Reference
- src/tools/batchUpdateBlocks.ts:6-40 (handler)The core handler function for the "batch_update_blocks" tool. It processes an array of update operations on Notion blocks, calling the Notion API for each, collecting results, and returning a success message with JSON details or handling errors.export const batchUpdateBlocks = async ( params: BatchUpdateBlocksParams ): Promise<CallToolResult> => { try { const results = []; for (const operation of params.operations) { const response = await notion.blocks.update({ block_id: operation.blockId, ...operation.data, }); results.push({ blockId: operation.blockId, success: true, response, }); } return { content: [ { type: "text", text: `Successfully updated ${params.operations.length} blocks`, }, { type: "text", text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { return handleNotionError(error); } };
- src/schema/blocks.ts:207-216 (schema)Zod schema defining the input parameters for batch_update_blocks: an array of objects each containing blockId (string) and data (TEXT_BLOCK_REQUEST_SCHEMA).export const BATCH_UPDATE_BLOCKS_SCHEMA = { operations: z .array( z.object({ blockId: z.string().describe("The ID of the block to update"), data: TEXT_BLOCK_REQUEST_SCHEMA.describe("The block data to update"), }) ) .describe("Array of update operations to perform in a single batch"), };
- src/tools/blocks.ts:30-31 (registration)Tool registration/dispatch logic within the blocks operation handler. Matches the "batch_update_blocks" action and delegates to the batchUpdateBlocks function.case "batch_update_blocks": return batchUpdateBlocks(params.payload.params);
- src/schema/blocks.ts:296-302 (schema)Part of the BLOCKS_OPERATION_SCHEMA discriminated union defining the "batch_update_blocks" action variant, including description and params schema reference.z.object({ action: z .literal("batch_update_blocks") .describe( "Use this action to perform batch update operations on blocks." ), params: z.object(BATCH_UPDATE_BLOCKS_SCHEMA),
- src/types/blocks.ts:43-44 (helper)TypeScript type definition and schema wrapper for BatchUpdateBlocksParams, inferred from the schema.export const batchUpdateBlocksSchema = z.object(BATCH_UPDATE_BLOCKS_SCHEMA); export type BatchUpdateBlocksParams = z.infer<typeof batchUpdateBlocksSchema>;