Skip to content

Commit bc26d1b

Browse files
committed
fix(notion): align integration with live API docs, add block retrieval coverage
- wire up notion_update_page in the block (was registered but unreachable — no dropdown option or subBlocks) - fix legacy NotionBlock outputs to cover all 17 operations, not just content/metadata - trim ID params (pageId, databaseId, parentId) before use in request URLs across 8 tool files - remove content required:true on create_page (Notion allows title-only pages) - remove dead unused NotionReadDatabaseParams interface - add notion_retrieve_block/_v2 tool for GET /v1/blocks/{id}, filling a gap in block CRUD coverage
1 parent ed1492b commit bc26d1b

13 files changed

Lines changed: 313 additions & 29 deletions

File tree

apps/sim/blocks/blocks/notion.ts

Lines changed: 190 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
3030
{ label: 'Read Page', id: 'notion_read' },
3131
{ label: 'Read Database', id: 'notion_read_database' },
3232
{ label: 'Create Page', id: 'notion_create_page' },
33+
{ label: 'Update Page Properties', id: 'notion_update_page' },
3334
{ label: 'Create Database', id: 'notion_create_database' },
3435
{ label: 'Add Database Row', id: 'notion_add_database_row' },
3536
{ label: 'Append Content', id: 'notion_write' },
3637
{ label: 'Append Block Children', id: 'notion_append_blocks' },
38+
{ label: 'Retrieve Block', id: 'notion_retrieve_block' },
3739
{ label: 'Retrieve Block Children', id: 'notion_retrieve_block_children' },
3840
{ label: 'Update Block', id: 'notion_update_block' },
3941
{ label: 'Delete Block', id: 'notion_delete_block' },
@@ -77,7 +79,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
7779
mode: 'basic',
7880
condition: {
7981
field: 'operation',
80-
value: ['notion_read', 'notion_write'],
82+
value: ['notion_read', 'notion_write', 'notion_update_page'],
8183
},
8284
required: true,
8385
},
@@ -91,7 +93,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
9193
mode: 'advanced',
9294
condition: {
9395
field: 'operation',
94-
value: ['notion_read', 'notion_write'],
96+
value: ['notion_read', 'notion_write', 'notion_update_page'],
9597
},
9698
required: true,
9799
},
@@ -192,7 +194,6 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
192194
field: 'operation',
193195
value: 'notion_create_page',
194196
},
195-
required: true,
196197
wandConfig: {
197198
enabled: true,
198199
prompt:
@@ -318,6 +319,22 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
318319
generationType: 'json-object',
319320
},
320321
},
322+
{
323+
id: 'properties',
324+
title: 'Properties to Update',
325+
type: 'code',
326+
placeholder: 'Enter page properties as JSON object',
327+
condition: { field: 'operation', value: 'notion_update_page' },
328+
required: true,
329+
wandConfig: {
330+
enabled: true,
331+
prompt:
332+
'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.',
333+
placeholder:
334+
'Describe the properties to update (e.g., "set status to Done, priority to High")...',
335+
generationType: 'json-object',
336+
},
337+
},
321338
{
322339
id: 'blockId',
323340
title: 'Page or Block ID',
@@ -328,6 +345,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
328345
field: 'operation',
329346
value: [
330347
'notion_append_blocks',
348+
'notion_retrieve_block',
331349
'notion_retrieve_block_children',
332350
'notion_update_block',
333351
'notion_delete_block',
@@ -449,6 +467,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
449467
'notion_add_database_row',
450468
'notion_update_page',
451469
'notion_append_blocks',
470+
'notion_retrieve_block',
452471
'notion_retrieve_block_children',
453472
'notion_update_block',
454473
'notion_delete_block',
@@ -480,6 +499,8 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
480499
return 'notion_add_database_row'
481500
case 'notion_append_blocks':
482501
return 'notion_append_blocks'
502+
case 'notion_retrieve_block':
503+
return 'notion_retrieve_block'
483504
case 'notion_retrieve_block_children':
484505
return 'notion_retrieve_block_children'
485506
case 'notion_update_block':
@@ -519,7 +540,8 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
519540
if (
520541
(operation === 'notion_create_page' ||
521542
operation === 'notion_create_database' ||
522-
operation === 'notion_add_database_row') &&
543+
operation === 'notion_add_database_row' ||
544+
operation === 'notion_update_page') &&
523545
properties
524546
) {
525547
if (typeof properties === 'string') {
@@ -651,17 +673,161 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
651673
userId: { type: 'string', description: 'User identifier' },
652674
},
653675
outputs: {
654-
// Common outputs across all Notion operations
676+
// Outputs for the original content/metadata-shaped operations
655677
content: {
656678
type: 'string',
657-
description: 'Page content, search results, or confirmation messages',
679+
description: 'Page content, comment text, search results, or confirmation messages',
680+
condition: {
681+
field: 'operation',
682+
value: [
683+
'notion_read',
684+
'notion_write',
685+
'notion_create_page',
686+
'notion_update_page',
687+
'notion_query_database',
688+
'notion_search',
689+
'notion_create_database',
690+
'notion_read_database',
691+
'notion_create_comment',
692+
],
693+
},
658694
},
659-
660-
// Metadata object containing operation-specific information
661695
metadata: {
662696
type: 'json',
663697
description:
664698
'Metadata containing operation-specific details including page/database info, results, and pagination data',
699+
condition: {
700+
field: 'operation',
701+
value: [
702+
'notion_read',
703+
'notion_write',
704+
'notion_create_page',
705+
'notion_update_page',
706+
'notion_query_database',
707+
'notion_search',
708+
'notion_create_database',
709+
'notion_read_database',
710+
],
711+
},
712+
},
713+
714+
// Outputs for the API-aligned flat-shaped operations added after the legacy block was hidden
715+
id: {
716+
type: 'string',
717+
description: 'Row, block, comment, or user ID',
718+
condition: {
719+
field: 'operation',
720+
value: [
721+
'notion_add_database_row',
722+
'notion_retrieve_block',
723+
'notion_update_block',
724+
'notion_delete_block',
725+
'notion_create_comment',
726+
'notion_retrieve_user',
727+
],
728+
},
729+
},
730+
url: {
731+
type: 'string',
732+
description: 'Notion page URL',
733+
condition: { field: 'operation', value: 'notion_add_database_row' },
734+
},
735+
title: {
736+
type: 'string',
737+
description: 'Row title',
738+
condition: { field: 'operation', value: 'notion_add_database_row' },
739+
},
740+
created_time: {
741+
type: 'string',
742+
description: 'Creation timestamp',
743+
condition: {
744+
field: 'operation',
745+
value: ['notion_add_database_row', 'notion_create_comment'],
746+
},
747+
},
748+
last_edited_time: {
749+
type: 'string',
750+
description: 'Last edit timestamp',
751+
condition: { field: 'operation', value: 'notion_add_database_row' },
752+
},
753+
results: {
754+
type: 'array',
755+
description: 'Array of results (blocks, comments, or users)',
756+
condition: {
757+
field: 'operation',
758+
value: [
759+
'notion_append_blocks',
760+
'notion_retrieve_block_children',
761+
'notion_list_comments',
762+
'notion_list_users',
763+
],
764+
},
765+
},
766+
has_more: {
767+
type: 'boolean',
768+
description: 'Whether more results are available',
769+
condition: {
770+
field: 'operation',
771+
value: [
772+
'notion_append_blocks',
773+
'notion_retrieve_block_children',
774+
'notion_list_comments',
775+
'notion_list_users',
776+
],
777+
},
778+
},
779+
next_cursor: {
780+
type: 'string',
781+
description: 'Cursor for pagination',
782+
condition: {
783+
field: 'operation',
784+
value: [
785+
'notion_append_blocks',
786+
'notion_retrieve_block_children',
787+
'notion_list_comments',
788+
'notion_list_users',
789+
],
790+
},
791+
},
792+
type: {
793+
type: 'string',
794+
description: 'Block type',
795+
condition: { field: 'operation', value: 'notion_update_block' },
796+
},
797+
block: {
798+
type: 'json',
799+
description: 'The full updated Notion block object',
800+
condition: { field: 'operation', value: 'notion_update_block' },
801+
},
802+
archived: {
803+
type: 'boolean',
804+
description: 'Whether the block was archived',
805+
condition: { field: 'operation', value: ['notion_update_block', 'notion_delete_block'] },
806+
},
807+
discussion_id: {
808+
type: 'string',
809+
description: 'Discussion thread ID',
810+
condition: { field: 'operation', value: 'notion_create_comment' },
811+
},
812+
rich_text: {
813+
type: 'json',
814+
description: 'Rich text array of the comment',
815+
condition: { field: 'operation', value: 'notion_create_comment' },
816+
},
817+
name: {
818+
type: 'string',
819+
description: 'User display name',
820+
condition: { field: 'operation', value: 'notion_retrieve_user' },
821+
},
822+
avatar_url: {
823+
type: 'string',
824+
description: 'User avatar image URL',
825+
condition: { field: 'operation', value: 'notion_retrieve_user' },
826+
},
827+
email: {
828+
type: 'string',
829+
description: 'User email address (person users only)',
830+
condition: { field: 'operation', value: 'notion_retrieve_user' },
665831
},
666832
},
667833
}
@@ -721,6 +887,7 @@ export const NotionV2Block: BlockConfig<any> = {
721887
'notion_create_database_v2',
722888
'notion_add_database_row_v2',
723889
'notion_append_blocks_v2',
890+
'notion_retrieve_block_v2',
724891
'notion_retrieve_block_children_v2',
725892
'notion_update_block_v2',
726893
'notion_delete_block_v2',
@@ -765,6 +932,7 @@ export const NotionV2Block: BlockConfig<any> = {
765932
'notion_add_database_row',
766933
'notion_read_database',
767934
'notion_update_page',
935+
'notion_retrieve_block',
768936
'notion_update_block',
769937
'notion_delete_block',
770938
'notion_create_comment',
@@ -843,21 +1011,29 @@ export const NotionV2Block: BlockConfig<any> = {
8431011
description: 'Whether content was successfully appended',
8441012
condition: { field: 'operation', value: 'notion_write' },
8451013
},
846-
// Block update/delete outputs
1014+
// Block retrieve/update/delete outputs
8471015
type: {
8481016
type: 'string',
8491017
description: 'Block type',
850-
condition: { field: 'operation', value: 'notion_update_block' },
1018+
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
8511019
},
8521020
block: {
8531021
type: 'json',
854-
description: 'The full updated Notion block object',
855-
condition: { field: 'operation', value: 'notion_update_block' },
1022+
description: 'The full Notion block object',
1023+
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
1024+
},
1025+
has_children: {
1026+
type: 'boolean',
1027+
description: 'Whether the block has nested blocks',
1028+
condition: { field: 'operation', value: 'notion_retrieve_block' },
8561029
},
8571030
archived: {
8581031
type: 'boolean',
859-
description: 'Whether the block was archived',
860-
condition: { field: 'operation', value: ['notion_update_block', 'notion_delete_block'] },
1032+
description: 'Whether the block is archived',
1033+
condition: {
1034+
field: 'operation',
1035+
value: ['notion_retrieve_block', 'notion_update_block', 'notion_delete_block'],
1036+
},
8611037
},
8621038
// Comment outputs
8631039
discussion_id: {

apps/sim/tools/notion/add_database_row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const notionAddDatabaseRowTool: ToolConfig<
6767
return {
6868
parent: {
6969
type: 'database_id',
70-
database_id: params.databaseId,
70+
database_id: params.databaseId.trim(),
7171
},
7272
properties: params.properties,
7373
}

apps/sim/tools/notion/create_database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const notionCreateDatabaseTool: ToolConfig<NotionCreateDatabaseParams, No
6565
const body = {
6666
parent: {
6767
type: 'page_id',
68-
page_id: params.parentId,
68+
page_id: params.parentId.trim(),
6969
},
7070
title: [
7171
{

apps/sim/tools/notion/create_page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const notionCreatePageTool: ToolConfig<NotionCreatePageParams, NotionResp
5858
const body: any = {
5959
parent: {
6060
type: 'page_id',
61-
page_id: params.parentId,
61+
page_id: params.parentId.trim(),
6262
},
6363
}
6464

apps/sim/tools/notion/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { notionListUsersTool, notionListUsersV2Tool } from '@/tools/notion/list_
1515
import { notionQueryDatabaseTool, notionQueryDatabaseV2Tool } from '@/tools/notion/query_database'
1616
import { notionReadTool, notionReadV2Tool } from '@/tools/notion/read'
1717
import { notionReadDatabaseTool, notionReadDatabaseV2Tool } from '@/tools/notion/read_database'
18+
import { notionRetrieveBlockTool, notionRetrieveBlockV2Tool } from '@/tools/notion/retrieve_block'
1819
import {
1920
notionRetrieveBlockChildrenTool,
2021
notionRetrieveBlockChildrenV2Tool,
@@ -37,6 +38,7 @@ export {
3738
notionCreateDatabaseTool,
3839
notionAddDatabaseRowTool,
3940
notionAppendBlocksTool,
41+
notionRetrieveBlockTool,
4042
notionRetrieveBlockChildrenTool,
4143
notionUpdateBlockTool,
4244
notionDeleteBlockTool,
@@ -55,6 +57,7 @@ export {
5557
notionCreateDatabaseV2Tool,
5658
notionAddDatabaseRowV2Tool,
5759
notionAppendBlocksV2Tool,
60+
notionRetrieveBlockV2Tool,
5861
notionRetrieveBlockChildrenV2Tool,
5962
notionUpdateBlockV2Tool,
6063
notionDeleteBlockV2Tool,

apps/sim/tools/notion/query_database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const notionQueryDatabaseTool: ToolConfig<NotionQueryDatabaseParams, Noti
5050

5151
request: {
5252
url: (params: NotionQueryDatabaseParams) => {
53-
return `https://api.notion.com/v1/databases/${params.databaseId}/query`
53+
return `https://api.notion.com/v1/databases/${params.databaseId.trim()}/query`
5454
},
5555
method: 'POST',
5656
headers: (params: NotionQueryDatabaseParams) => {

0 commit comments

Comments
 (0)