diff --git a/apps/docs/content/docs/en/integrations/notion.mdx b/apps/docs/content/docs/en/integrations/notion.mdx index af14a062afc..4f397435ee5 100644 --- a/apps/docs/content/docs/en/integrations/notion.mdx +++ b/apps/docs/content/docs/en/integrations/notion.mdx @@ -145,6 +145,7 @@ Query and filter Notion database entries with advanced filtering | `filter` | string | No | Filter conditions as JSON \(optional\) | | `sorts` | string | No | Sort criteria as JSON array \(optional\) | | `pageSize` | number | No | Number of results to return \(default: 100, max: 100\) | +| `startCursor` | string | No | Pagination cursor returned by a previous request | #### Output @@ -200,6 +201,7 @@ Search across all pages and databases in Notion workspace | `query` | string | No | Search terms to find pages and databases \(leave empty to get all pages\) | | `filterType` | string | No | Filter by object type: "page", "database", or leave empty for all | | `pageSize` | number | No | Number of results to return \(default: 100, max: 100\) | +| `startCursor` | string | No | Pagination cursor returned by a previous request | #### Output @@ -302,8 +304,44 @@ Append new block children (content) to a Notion page or block | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | +| `discussion_id` | string | Discussion thread ID | +| `name` | string | User display name | +| `avatar_url` | string | User avatar image URL | +| `email` | string | User email address \(person users only\) | + +### `notion_retrieve_block` + +Retrieve a single Notion block by its UUID, including its type-specific content + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `blockId` | string | Yes | The UUID of the block to retrieve | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `content` | string | Page content in markdown format, or comment text for create comment | +| `title` | string | Page or database title | +| `url` | string | Notion URL | +| `id` | string | Page, database, block, comment, or user ID | +| `created_time` | string | Creation timestamp | +| `last_edited_time` | string | Last edit timestamp | +| `results` | array | Array of results \(pages, blocks, comments, or users\) | +| `has_more` | boolean | Whether more results are available | +| `next_cursor` | string | Cursor for pagination | +| `total_results` | number | Number of results returned | +| `properties` | json | Database properties schema | +| `appended` | boolean | Whether content was successfully appended | +| `type` | string | Block type | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -338,8 +376,9 @@ Retrieve the block children (content) of a Notion page or block | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -374,8 +413,9 @@ Update the content or archived state of a single Notion block | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -408,8 +448,9 @@ Delete (move to trash) a single Notion block | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -444,8 +485,9 @@ Create a comment on a Notion page or within an existing discussion thread | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -480,8 +522,9 @@ List unresolved comments on a Notion page or block | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -515,8 +558,9 @@ List all users (members and bots) in the Notion workspace | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | @@ -549,8 +593,9 @@ Retrieve a single Notion user by their UUID | `properties` | json | Database properties schema | | `appended` | boolean | Whether content was successfully appended | | `type` | string | Block type | -| `block` | json | The full updated Notion block object | -| `archived` | boolean | Whether the block was archived | +| `block` | json | The full Notion block object | +| `has_children` | boolean | Whether the block has nested blocks | +| `archived` | boolean | Whether the block is archived | | `discussion_id` | string | Discussion thread ID | | `name` | string | User display name | | `avatar_url` | string | User avatar image URL | diff --git a/apps/sim/blocks/blocks/notion.ts b/apps/sim/blocks/blocks/notion.ts index 03bfa2b8257..db2fecf3e09 100644 --- a/apps/sim/blocks/blocks/notion.ts +++ b/apps/sim/blocks/blocks/notion.ts @@ -30,10 +30,12 @@ export const NotionBlock: BlockConfig = { { label: 'Read Page', id: 'notion_read' }, { label: 'Read Database', id: 'notion_read_database' }, { label: 'Create Page', id: 'notion_create_page' }, + { label: 'Update Page Properties', id: 'notion_update_page' }, { label: 'Create Database', id: 'notion_create_database' }, { label: 'Add Database Row', id: 'notion_add_database_row' }, { label: 'Append Content', id: 'notion_write' }, { label: 'Append Block Children', id: 'notion_append_blocks' }, + { label: 'Retrieve Block', id: 'notion_retrieve_block' }, { label: 'Retrieve Block Children', id: 'notion_retrieve_block_children' }, { label: 'Update Block', id: 'notion_update_block' }, { label: 'Delete Block', id: 'notion_delete_block' }, @@ -77,7 +79,7 @@ export const NotionBlock: BlockConfig = { mode: 'basic', condition: { field: 'operation', - value: ['notion_read', 'notion_write'], + value: ['notion_read', 'notion_write', 'notion_update_page'], }, required: true, }, @@ -91,7 +93,7 @@ export const NotionBlock: BlockConfig = { mode: 'advanced', condition: { field: 'operation', - value: ['notion_read', 'notion_write'], + value: ['notion_read', 'notion_write', 'notion_update_page'], }, required: true, }, @@ -192,7 +194,6 @@ export const NotionBlock: BlockConfig = { field: 'operation', value: 'notion_create_page', }, - required: true, wandConfig: { enabled: true, prompt: @@ -243,6 +244,7 @@ export const NotionBlock: BlockConfig = { 'notion_retrieve_block_children', 'notion_list_comments', 'notion_list_users', + 'notion_search', ], }, }, @@ -318,6 +320,22 @@ export const NotionBlock: BlockConfig = { generationType: 'json-object', }, }, + { + id: 'properties', + title: 'Properties to Update', + type: 'code', + placeholder: 'Enter page properties as JSON object', + condition: { field: 'operation', value: 'notion_update_page' }, + required: true, + wandConfig: { + enabled: true, + prompt: + 'Generate Notion page properties to update in JSON format based on the user\'s description. Properties must match the parent database schema. Common formats: Title: {"Name": {"title": [{"text": {"content": "Value"}}]}}, Text: {"Description": {"rich_text": [{"text": {"content": "Value"}}]}}, Number: {"Price": {"number": 10}}, Select: {"Status": {"select": {"name": "Done"}}}, Multi-select: {"Tags": {"multi_select": [{"name": "Tag1"}]}}, Date: {"Due": {"date": {"start": "2024-01-01"}}}, Checkbox: {"Done": {"checkbox": true}}. Return ONLY valid JSON - no explanations.', + placeholder: + 'Describe the properties to update (e.g., "set status to Done, priority to High")...', + generationType: 'json-object', + }, + }, { id: 'blockId', title: 'Page or Block ID', @@ -328,6 +346,7 @@ export const NotionBlock: BlockConfig = { field: 'operation', value: [ 'notion_append_blocks', + 'notion_retrieve_block', 'notion_retrieve_block_children', 'notion_update_block', 'notion_delete_block', @@ -433,7 +452,13 @@ export const NotionBlock: BlockConfig = { mode: 'advanced', condition: { field: 'operation', - value: ['notion_retrieve_block_children', 'notion_list_comments', 'notion_list_users'], + value: [ + 'notion_retrieve_block_children', + 'notion_list_comments', + 'notion_list_users', + 'notion_query_database', + 'notion_search', + ], }, }, ], @@ -449,6 +474,7 @@ export const NotionBlock: BlockConfig = { 'notion_add_database_row', 'notion_update_page', 'notion_append_blocks', + 'notion_retrieve_block', 'notion_retrieve_block_children', 'notion_update_block', 'notion_delete_block', @@ -480,6 +506,8 @@ export const NotionBlock: BlockConfig = { return 'notion_add_database_row' case 'notion_append_blocks': return 'notion_append_blocks' + case 'notion_retrieve_block': + return 'notion_retrieve_block' case 'notion_retrieve_block_children': return 'notion_retrieve_block_children' case 'notion_update_block': @@ -519,7 +547,8 @@ export const NotionBlock: BlockConfig = { if ( (operation === 'notion_create_page' || operation === 'notion_create_database' || - operation === 'notion_add_database_row') && + operation === 'notion_add_database_row' || + operation === 'notion_update_page') && properties ) { if (typeof properties === 'string') { @@ -651,17 +680,169 @@ export const NotionBlock: BlockConfig = { userId: { type: 'string', description: 'User identifier' }, }, outputs: { - // Common outputs across all Notion operations + // Outputs for the original content/metadata-shaped operations content: { type: 'string', - description: 'Page content, search results, or confirmation messages', + description: 'Page content, comment text, search results, or confirmation messages', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_write', + 'notion_create_page', + 'notion_update_page', + 'notion_query_database', + 'notion_search', + 'notion_create_database', + 'notion_read_database', + 'notion_create_comment', + ], + }, }, - - // Metadata object containing operation-specific information metadata: { type: 'json', description: 'Metadata containing operation-specific details including page/database info, results, and pagination data', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_write', + 'notion_create_page', + 'notion_update_page', + 'notion_query_database', + 'notion_search', + 'notion_create_database', + 'notion_read_database', + ], + }, + }, + + // Outputs for the API-aligned flat-shaped operations added after the legacy block was hidden + id: { + type: 'string', + description: 'Row, block, comment, or user ID', + condition: { + field: 'operation', + value: [ + 'notion_add_database_row', + 'notion_retrieve_block', + 'notion_update_block', + 'notion_delete_block', + 'notion_create_comment', + 'notion_retrieve_user', + ], + }, + }, + url: { + type: 'string', + description: 'Notion page URL', + condition: { field: 'operation', value: 'notion_add_database_row' }, + }, + title: { + type: 'string', + description: 'Row title', + condition: { field: 'operation', value: 'notion_add_database_row' }, + }, + created_time: { + type: 'string', + description: 'Creation timestamp', + condition: { + field: 'operation', + value: ['notion_add_database_row', 'notion_create_comment'], + }, + }, + last_edited_time: { + type: 'string', + description: 'Last edit timestamp', + condition: { field: 'operation', value: 'notion_add_database_row' }, + }, + results: { + type: 'array', + description: 'Array of results (blocks, comments, or users)', + condition: { + field: 'operation', + value: [ + 'notion_append_blocks', + 'notion_retrieve_block_children', + 'notion_list_comments', + 'notion_list_users', + ], + }, + }, + has_more: { + type: 'boolean', + description: 'Whether more results are available', + condition: { + field: 'operation', + value: [ + 'notion_append_blocks', + 'notion_retrieve_block_children', + 'notion_list_comments', + 'notion_list_users', + ], + }, + }, + next_cursor: { + type: 'string', + description: 'Cursor for pagination', + condition: { + field: 'operation', + value: [ + 'notion_append_blocks', + 'notion_retrieve_block_children', + 'notion_list_comments', + 'notion_list_users', + ], + }, + }, + type: { + type: 'string', + description: 'Block type', + condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] }, + }, + block: { + type: 'json', + description: 'The full Notion block object', + condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] }, + }, + has_children: { + type: 'boolean', + description: 'Whether the block has nested blocks', + condition: { field: 'operation', value: 'notion_retrieve_block' }, + }, + archived: { + type: 'boolean', + description: 'Whether the block is archived', + condition: { + field: 'operation', + value: ['notion_retrieve_block', 'notion_update_block', 'notion_delete_block'], + }, + }, + discussion_id: { + type: 'string', + description: 'Discussion thread ID', + condition: { field: 'operation', value: 'notion_create_comment' }, + }, + rich_text: { + type: 'json', + description: 'Rich text array of the comment', + condition: { field: 'operation', value: 'notion_create_comment' }, + }, + name: { + type: 'string', + description: 'User display name', + condition: { field: 'operation', value: 'notion_retrieve_user' }, + }, + avatar_url: { + type: 'string', + description: 'User avatar image URL', + condition: { field: 'operation', value: 'notion_retrieve_user' }, + }, + email: { + type: 'string', + description: 'User email address (person users only)', + condition: { field: 'operation', value: 'notion_retrieve_user' }, }, }, } @@ -721,6 +902,7 @@ export const NotionV2Block: BlockConfig = { 'notion_create_database_v2', 'notion_add_database_row_v2', 'notion_append_blocks_v2', + 'notion_retrieve_block_v2', 'notion_retrieve_block_children_v2', 'notion_update_block_v2', 'notion_delete_block_v2', @@ -749,10 +931,32 @@ export const NotionV2Block: BlockConfig = { title: { type: 'string', description: 'Page or database title', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_create_page', + 'notion_update_page', + 'notion_create_database', + 'notion_read_database', + 'notion_add_database_row', + ], + }, }, url: { type: 'string', description: 'Notion URL', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_create_page', + 'notion_update_page', + 'notion_create_database', + 'notion_read_database', + 'notion_add_database_row', + ], + }, }, id: { type: 'string', @@ -765,6 +969,7 @@ export const NotionV2Block: BlockConfig = { 'notion_add_database_row', 'notion_read_database', 'notion_update_page', + 'notion_retrieve_block', 'notion_update_block', 'notion_delete_block', 'notion_create_comment', @@ -775,10 +980,31 @@ export const NotionV2Block: BlockConfig = { created_time: { type: 'string', description: 'Creation timestamp', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_create_page', + 'notion_create_database', + 'notion_read_database', + 'notion_add_database_row', + 'notion_create_comment', + ], + }, }, last_edited_time: { type: 'string', description: 'Last edit timestamp', + condition: { + field: 'operation', + value: [ + 'notion_read', + 'notion_create_page', + 'notion_update_page', + 'notion_read_database', + 'notion_add_database_row', + ], + }, }, // List/query/search outputs results: { @@ -843,21 +1069,29 @@ export const NotionV2Block: BlockConfig = { description: 'Whether content was successfully appended', condition: { field: 'operation', value: 'notion_write' }, }, - // Block update/delete outputs + // Block retrieve/update/delete outputs type: { type: 'string', description: 'Block type', - condition: { field: 'operation', value: 'notion_update_block' }, + condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] }, }, block: { type: 'json', - description: 'The full updated Notion block object', - condition: { field: 'operation', value: 'notion_update_block' }, + description: 'The full Notion block object', + condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] }, + }, + has_children: { + type: 'boolean', + description: 'Whether the block has nested blocks', + condition: { field: 'operation', value: 'notion_retrieve_block' }, }, archived: { type: 'boolean', - description: 'Whether the block was archived', - condition: { field: 'operation', value: ['notion_update_block', 'notion_delete_block'] }, + description: 'Whether the block is archived', + condition: { + field: 'operation', + value: ['notion_retrieve_block', 'notion_update_block', 'notion_delete_block'], + }, }, // Comment outputs discussion_id: { diff --git a/apps/sim/tools/notion/add_database_row.ts b/apps/sim/tools/notion/add_database_row.ts index 53da6718f2f..eb528032480 100644 --- a/apps/sim/tools/notion/add_database_row.ts +++ b/apps/sim/tools/notion/add_database_row.ts @@ -67,7 +67,7 @@ export const notionAddDatabaseRowTool: ToolConfig< return { parent: { type: 'database_id', - database_id: params.databaseId, + database_id: params.databaseId.trim(), }, properties: params.properties, } diff --git a/apps/sim/tools/notion/create_database.ts b/apps/sim/tools/notion/create_database.ts index 2ddda97e316..a67e4020c98 100644 --- a/apps/sim/tools/notion/create_database.ts +++ b/apps/sim/tools/notion/create_database.ts @@ -65,7 +65,7 @@ export const notionCreateDatabaseTool: ToolConfig { - return `https://api.notion.com/v1/databases/${params.databaseId}/query` + return `https://api.notion.com/v1/databases/${params.databaseId.trim()}/query` }, method: 'POST', headers: (params: NotionQueryDatabaseParams) => { @@ -90,6 +96,11 @@ export const notionQueryDatabaseTool: ToolConfig = { request: { url: (params: NotionReadParams) => { - return `https://api.notion.com/v1/pages/${params.pageId}` + return `https://api.notion.com/v1/pages/${params.pageId.trim()}` }, method: 'GET', headers: (params: NotionReadParams) => { @@ -64,7 +64,7 @@ export const notionReadTool: ToolConfig = { } // Now fetch the page content using blocks endpoint - const pageId = params?.pageId + const pageId = params?.pageId?.trim() const accessToken = params?.accessToken if (!pageId || !accessToken) { @@ -212,7 +212,7 @@ export const notionReadV2Tool: ToolConfig { - return `https://api.notion.com/v1/databases/${params.databaseId}` + return `https://api.notion.com/v1/databases/${params.databaseId.trim()}` }, method: 'GET', headers: (params: NotionReadDatabaseParams) => { diff --git a/apps/sim/tools/notion/retrieve_block.ts b/apps/sim/tools/notion/retrieve_block.ts new file mode 100644 index 00000000000..cf4c9efb771 --- /dev/null +++ b/apps/sim/tools/notion/retrieve_block.ts @@ -0,0 +1,107 @@ +import { BLOCK_OUTPUT_PROPERTIES } from '@/tools/notion/types' +import type { ToolConfig } from '@/tools/types' + +export interface NotionRetrieveBlockParams { + blockId: string + accessToken: string +} + +interface NotionRetrieveBlockResponse { + success: boolean + output: { + id: string + type: string + has_children: boolean + archived: boolean + block: Record + } +} + +export const notionRetrieveBlockTool: ToolConfig< + NotionRetrieveBlockParams, + NotionRetrieveBlockResponse +> = { + id: 'notion_retrieve_block', + name: 'Notion Retrieve Block', + description: 'Retrieve a single Notion block by its UUID, including its type-specific content', + version: '1.0.0', + + oauth: { + required: true, + provider: 'notion', + }, + + params: { + accessToken: { + type: 'string', + required: true, + visibility: 'hidden', + description: 'Notion OAuth access token', + }, + blockId: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'The UUID of the block to retrieve', + }, + }, + + request: { + url: (params: NotionRetrieveBlockParams) => + `https://api.notion.com/v1/blocks/${params.blockId.trim()}`, + method: 'GET', + headers: (params: NotionRetrieveBlockParams) => { + if (!params.accessToken) { + throw new Error('Access token is required') + } + + return { + Authorization: `Bearer ${params.accessToken}`, + 'Notion-Version': '2022-06-28', + 'Content-Type': 'application/json', + } + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + return { + success: response.ok, + output: { + id: data.id, + type: data.type ?? '', + has_children: data.has_children ?? false, + archived: data.archived ?? false, + block: data, + }, + } + }, + + outputs: { + id: BLOCK_OUTPUT_PROPERTIES.id, + type: BLOCK_OUTPUT_PROPERTIES.type, + has_children: BLOCK_OUTPUT_PROPERTIES.has_children, + archived: BLOCK_OUTPUT_PROPERTIES.archived, + block: { + type: 'object', + description: + 'The full Notion block object. Includes a type-specific field (e.g. paragraph, heading_1, image) whose shape varies by block type and is not enumerated below — read it directly off this object.', + properties: BLOCK_OUTPUT_PROPERTIES, + }, + }, +} + +export const notionRetrieveBlockV2Tool: ToolConfig< + NotionRetrieveBlockParams, + NotionRetrieveBlockResponse +> = { + id: 'notion_retrieve_block_v2', + name: 'Notion Retrieve Block', + description: 'Retrieve a single Notion block by its UUID, including its type-specific content', + version: '2.0.0', + oauth: notionRetrieveBlockTool.oauth, + params: notionRetrieveBlockTool.params, + request: notionRetrieveBlockTool.request, + transformResponse: notionRetrieveBlockTool.transformResponse, + outputs: notionRetrieveBlockTool.outputs, +} diff --git a/apps/sim/tools/notion/search.ts b/apps/sim/tools/notion/search.ts index d0fa3e1ec24..a0feba29822 100644 --- a/apps/sim/tools/notion/search.ts +++ b/apps/sim/tools/notion/search.ts @@ -39,6 +39,12 @@ export const notionSearchTool: ToolConfig = visibility: 'user-or-llm', description: 'Number of results to return (default: 100, max: 100)', }, + startCursor: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Pagination cursor returned by a previous request', + }, }, request: { @@ -80,6 +86,11 @@ export const notionSearchTool: ToolConfig = body.page_size = Math.min(Number(params.pageSize), 100) } + // Add pagination cursor if provided + if (params.startCursor) { + body.start_cursor = params.startCursor.trim() + } + return body }, }, diff --git a/apps/sim/tools/notion/types.ts b/apps/sim/tools/notion/types.ts index 448d7f8635d..2dc15428d4d 100644 --- a/apps/sim/tools/notion/types.ts +++ b/apps/sim/tools/notion/types.ts @@ -190,15 +190,6 @@ export const FILE_OUTPUT_PROPERTIES = { }, } as const satisfies Record -/** - * Complete file output definition - */ -export const FILE_OUTPUT: OutputProperty = { - type: 'object', - description: 'File object', - properties: FILE_OUTPUT_PROPERTIES, -} - /** * Emoji object properties. * @see https://developers.notion.com/reference/emoji-object @@ -308,61 +299,6 @@ export const PAGE_OUTPUT: OutputProperty = { properties: PAGE_OUTPUT_PROPERTIES, } -/** - * Simplified page output properties for read operations (flattened structure). - * Used by notion_read and notion_read_v2 tools. - */ -export const PAGE_READ_OUTPUT_PROPERTIES = { - content: { - type: 'string', - description: 'Page content in markdown format with headers, paragraphs, lists, and todos', - }, - title: { type: 'string', description: 'Page title' }, - url: { type: 'string', description: 'Notion page URL' }, - created_time: { type: 'string', description: 'ISO 8601 creation timestamp' }, - last_edited_time: { type: 'string', description: 'ISO 8601 last edit timestamp' }, -} as const satisfies Record - -/** - * Page metadata output properties for legacy tools. - * Used by notion_read, notion_create_page, notion_update_page. - */ -export const PAGE_METADATA_OUTPUT_PROPERTIES = { - title: { type: 'string', description: 'Page title' }, - lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' }, - createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' }, - url: { type: 'string', description: 'Notion page URL' }, -} as const satisfies Record - -/** - * Page metadata output for create/update operations. - */ -export const PAGE_MUTATION_METADATA_OUTPUT_PROPERTIES = { - title: { type: 'string', description: 'Page title' }, - pageId: { type: 'string', description: 'Page UUID' }, - url: { type: 'string', description: 'Notion page URL' }, - lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' }, - createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' }, -} as const satisfies Record - -/** - * Complete page metadata output definition - */ -export const PAGE_METADATA_OUTPUT: OutputProperty = { - type: 'object', - description: 'Page metadata including title, URL, and timestamps', - properties: PAGE_METADATA_OUTPUT_PROPERTIES, -} - -/** - * Page mutation metadata output definition (for create/update) - */ -export const PAGE_MUTATION_METADATA_OUTPUT: OutputProperty = { - type: 'object', - description: 'Page metadata including title, page ID, URL, and timestamps', - properties: PAGE_MUTATION_METADATA_OUTPUT_PROPERTIES, -} - /** * Common database object properties from Notion API. * @see https://developers.notion.com/reference/database @@ -400,28 +336,6 @@ export const DATABASE_OUTPUT: OutputProperty = { properties: DATABASE_OUTPUT_PROPERTIES, } -/** - * Database metadata output properties for legacy tools. - * Used by notion_read_database, notion_create_database. - */ -export const DATABASE_METADATA_OUTPUT_PROPERTIES = { - id: { type: 'string', description: 'Database UUID' }, - title: { type: 'string', description: 'Database title' }, - url: { type: 'string', description: 'Notion database URL' }, - createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' }, - lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' }, - properties: { type: 'object', description: 'Database properties schema' }, -} as const satisfies Record - -/** - * Complete database metadata output definition - */ -export const DATABASE_METADATA_OUTPUT: OutputProperty = { - type: 'object', - description: 'Database metadata including title, ID, URL, timestamps, and properties schema', - properties: DATABASE_METADATA_OUTPUT_PROPERTIES, -} - /** * Block object properties from Notion API. * @see https://developers.notion.com/reference/block @@ -491,25 +405,6 @@ export const SEARCH_RESULTS_OUTPUT: OutputProperty = { }, } -/** - * Search metadata output properties for legacy tools. - */ -export const SEARCH_METADATA_OUTPUT_PROPERTIES = { - totalResults: { type: 'number', description: 'Number of results returned' }, - hasMore: { type: 'boolean', description: 'Whether more results are available' }, - nextCursor: { type: 'string', description: 'Cursor for next page of results', optional: true }, - results: SEARCH_RESULTS_OUTPUT, -} as const satisfies Record - -/** - * Complete search metadata output definition - */ -export const SEARCH_METADATA_OUTPUT: OutputProperty = { - type: 'object', - description: 'Search metadata including total results count, pagination info, and raw results', - properties: SEARCH_METADATA_OUTPUT_PROPERTIES, -} - /** * Database query results array output with page items */ @@ -522,43 +417,6 @@ export const DATABASE_QUERY_RESULTS_OUTPUT: OutputProperty = { }, } -/** - * Query metadata output properties for legacy tools. - */ -export const QUERY_METADATA_OUTPUT_PROPERTIES = { - totalResults: { type: 'number', description: 'Number of results returned' }, - hasMore: { type: 'boolean', description: 'Whether more results are available' }, - nextCursor: { type: 'string', description: 'Cursor for next page of results', optional: true }, - results: DATABASE_QUERY_RESULTS_OUTPUT, -} as const satisfies Record - -/** - * Complete query metadata output definition - */ -export const QUERY_METADATA_OUTPUT: OutputProperty = { - type: 'object', - description: 'Query metadata including total results, pagination info, and raw results array', - properties: QUERY_METADATA_OUTPUT_PROPERTIES, -} - -/** - * Row output properties for add_database_row operations. - */ -export const ROW_OUTPUT_PROPERTIES = { - id: { type: 'string', description: 'Row (page) UUID' }, - url: { type: 'string', description: 'Notion page URL' }, - title: { type: 'string', description: 'Row title' }, - created_time: { type: 'string', description: 'ISO 8601 creation timestamp' }, - last_edited_time: { type: 'string', description: 'ISO 8601 last edit timestamp' }, -} as const satisfies Record - -/** - * Write operation output properties. - */ -export const WRITE_OUTPUT_PROPERTIES = { - appended: { type: 'boolean', description: 'Whether content was successfully appended' }, -} as const satisfies Record - /** * Comment object properties from Notion API. * @see https://developers.notion.com/reference/comment-object @@ -574,15 +432,6 @@ export const COMMENT_OUTPUT_PROPERTIES = { rich_text: RICH_TEXT_ARRAY_OUTPUT, } as const satisfies Record -/** - * Complete comment output definition for array items - */ -export const COMMENT_OUTPUT: OutputProperty = { - type: 'object', - description: 'Notion comment object', - properties: COMMENT_OUTPUT_PROPERTIES, -} - /** * Array of block objects (used by append/retrieve block children). */ @@ -668,6 +517,7 @@ export interface NotionQueryDatabaseParams { filter?: string sorts?: string pageSize?: number + startCursor?: string accessToken: string } @@ -675,6 +525,7 @@ export interface NotionSearchParams { query?: string filterType?: string pageSize?: number + startCursor?: string accessToken: string } @@ -685,11 +536,6 @@ export interface NotionCreateDatabaseParams { accessToken: string } -interface NotionReadDatabaseParams { - databaseId: string - accessToken: string -} - export interface NotionAddDatabaseRowParams { databaseId: string properties: Record diff --git a/apps/sim/tools/notion/update_page.ts b/apps/sim/tools/notion/update_page.ts index 3babd475a8f..7b36c0b9f21 100644 --- a/apps/sim/tools/notion/update_page.ts +++ b/apps/sim/tools/notion/update_page.ts @@ -36,7 +36,7 @@ export const notionUpdatePageTool: ToolConfig { - return `https://api.notion.com/v1/pages/${params.pageId}` + return `https://api.notion.com/v1/pages/${params.pageId.trim()}` }, method: 'PATCH', headers: (params: NotionUpdatePageParams) => { diff --git a/apps/sim/tools/notion/write.ts b/apps/sim/tools/notion/write.ts index d2ac89aaf34..f3437b4fd73 100644 --- a/apps/sim/tools/notion/write.ts +++ b/apps/sim/tools/notion/write.ts @@ -35,7 +35,7 @@ export const notionWriteTool: ToolConfig = { request: { url: (params: NotionWriteParams) => { - return `https://api.notion.com/v1/blocks/${params.pageId}/children` + return `https://api.notion.com/v1/blocks/${params.pageId.trim()}/children` }, method: 'PATCH', headers: (params: NotionWriteParams) => { diff --git a/apps/sim/tools/registry.ts b/apps/sim/tools/registry.ts index fa950a2c023..4fcda0f1cd4 100644 --- a/apps/sim/tools/registry.ts +++ b/apps/sim/tools/registry.ts @@ -2489,6 +2489,8 @@ import { notionReadV2Tool, notionRetrieveBlockChildrenTool, notionRetrieveBlockChildrenV2Tool, + notionRetrieveBlockTool, + notionRetrieveBlockV2Tool, notionRetrieveUserTool, notionRetrieveUserV2Tool, notionSearchTool, @@ -5528,6 +5530,7 @@ export const tools: Record = { notion_add_database_row: notionAddDatabaseRowTool, notion_update_page: notionUpdatePageTool, notion_append_blocks: notionAppendBlocksTool, + notion_retrieve_block: notionRetrieveBlockTool, notion_retrieve_block_children: notionRetrieveBlockChildrenTool, notion_update_block: notionUpdateBlockTool, notion_delete_block: notionDeleteBlockTool, @@ -5545,6 +5548,7 @@ export const tools: Record = { notion_update_page_v2: notionUpdatePageV2Tool, notion_add_database_row_v2: notionAddDatabaseRowV2Tool, notion_append_blocks_v2: notionAppendBlocksV2Tool, + notion_retrieve_block_v2: notionRetrieveBlockV2Tool, notion_retrieve_block_children_v2: notionRetrieveBlockChildrenV2Tool, notion_update_block_v2: notionUpdateBlockV2Tool, notion_delete_block_v2: notionDeleteBlockV2Tool,