Skip to content

Commit 04f7cd2

Browse files
BillLeoutsakosvl346Bill Leoutsakos
andauthored
fix(notion): resolve custom page title properties (#7323)
Co-authored-by: Bill Leoutsakos <billleoutsakos@Bills-MacBook-Pro.local>
1 parent bd7995e commit 04f7cd2

5 files changed

Lines changed: 73 additions & 75 deletions

File tree

apps/sim/lib/selectors/server/providers/notion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Notion server selector adapter', () => {
4747
object: 'page',
4848
id: 'page-provider-id',
4949
properties: {
50-
Name: { type: 'title', title: [{ plain_text: 'Planning' }] },
50+
Project: { type: 'title', title: [{ plain_text: 'Planning' }] },
5151
},
5252
}),
5353
{ status: 200 }

apps/sim/tools/notion/create_page.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionCreatePageParams, NotionResponse } from '@/tools/notion/types'
22
import { PAGE_OUTPUT_PROPERTIES } from '@/tools/notion/types'
3+
import { extractTitle } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
export const notionCreatePageTool: ToolConfig<NotionCreatePageParams, NotionResponse> = {
@@ -105,18 +106,7 @@ export const notionCreatePageTool: ToolConfig<NotionCreatePageParams, NotionResp
105106

106107
transformResponse: async (response: Response) => {
107108
const data = await response.json()
108-
let pageTitle = 'Untitled'
109-
110-
if (data.properties?.title) {
111-
const titleProperty = data.properties.title
112-
if (
113-
titleProperty.title &&
114-
Array.isArray(titleProperty.title) &&
115-
titleProperty.title.length > 0
116-
) {
117-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
118-
}
119-
}
109+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
120110

121111
return {
122112
success: true,
@@ -178,18 +168,7 @@ export const notionCreatePageV2Tool: ToolConfig<
178168

179169
transformResponse: async (response: Response) => {
180170
const data = await response.json()
181-
let pageTitle = 'Untitled'
182-
183-
if (data.properties?.title) {
184-
const titleProperty = data.properties.title
185-
if (
186-
titleProperty.title &&
187-
Array.isArray(titleProperty.title) &&
188-
titleProperty.title.length > 0
189-
) {
190-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
191-
}
192-
}
171+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
193172

194173
return {
195174
success: true,

apps/sim/tools/notion/read.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionReadParams, NotionResponse } from '@/tools/notion/types'
22
import { PAGE_OUTPUT_PROPERTIES } from '@/tools/notion/types'
3+
import { extractTitle } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
export const notionReadTool: ToolConfig<NotionReadParams, NotionResponse> = {
@@ -49,19 +50,7 @@ export const notionReadTool: ToolConfig<NotionReadParams, NotionResponse> = {
4950

5051
transformResponse: async (response: Response, params?: NotionReadParams) => {
5152
const data = await response.json()
52-
let pageTitle = 'Untitled'
53-
54-
// Extract title from properties
55-
if (data.properties?.title) {
56-
const titleProperty = data.properties.title
57-
if (
58-
titleProperty.title &&
59-
Array.isArray(titleProperty.title) &&
60-
titleProperty.title.length > 0
61-
) {
62-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
63-
}
64-
}
53+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
6554

6655
// Now fetch the page content using blocks endpoint
6756
const pageId = params?.pageId?.trim()
@@ -199,18 +188,7 @@ export const notionReadV2Tool: ToolConfig<NotionReadParams, NotionReadV2Response
199188

200189
transformResponse: async (response: Response, params?: NotionReadParams) => {
201190
const data = await response.json()
202-
let pageTitle = 'Untitled'
203-
204-
if (data.properties?.title) {
205-
const titleProperty = data.properties.title
206-
if (
207-
titleProperty.title &&
208-
Array.isArray(titleProperty.title) &&
209-
titleProperty.title.length > 0
210-
) {
211-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
212-
}
213-
}
191+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
214192

215193
const pageId = params?.pageId?.trim()
216194
const accessToken = params?.accessToken
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { notionCreatePageTool, notionCreatePageV2Tool } from '@/tools/notion/create_page'
6+
import { notionReadTool, notionReadV2Tool } from '@/tools/notion/read'
7+
import { notionUpdatePageTool, notionUpdatePageV2Tool } from '@/tools/notion/update_page'
8+
9+
const PAGE_TITLE = 'Project Apollo'
10+
11+
function pageResponse(): Response {
12+
return Response.json({
13+
id: 'page-1',
14+
url: 'https://www.notion.so/page-1',
15+
created_time: '2026-08-01T00:00:00.000Z',
16+
last_edited_time: '2026-08-02T00:00:00.000Z',
17+
properties: {
18+
Project: {
19+
id: 'title',
20+
type: 'title',
21+
title: [{ plain_text: PAGE_TITLE }],
22+
},
23+
},
24+
})
25+
}
26+
27+
const responseCases = [
28+
{
29+
id: notionReadTool.id,
30+
title: async () =>
31+
(await notionReadTool.transformResponse!(pageResponse())).output.metadata.title,
32+
},
33+
{
34+
id: notionReadV2Tool.id,
35+
title: async () => (await notionReadV2Tool.transformResponse!(pageResponse())).output.title,
36+
},
37+
{
38+
id: notionCreatePageTool.id,
39+
title: async () =>
40+
(await notionCreatePageTool.transformResponse!(pageResponse())).output.metadata.title,
41+
},
42+
{
43+
id: notionCreatePageV2Tool.id,
44+
title: async () =>
45+
(await notionCreatePageV2Tool.transformResponse!(pageResponse())).output.title,
46+
},
47+
{
48+
id: notionUpdatePageTool.id,
49+
title: async () =>
50+
(await notionUpdatePageTool.transformResponse!(pageResponse())).output.metadata.title,
51+
},
52+
{
53+
id: notionUpdatePageV2Tool.id,
54+
title: async () =>
55+
(await notionUpdatePageV2Tool.transformResponse!(pageResponse())).output.title,
56+
},
57+
]
58+
59+
describe('Notion page title responses', () => {
60+
it.each(responseCases)('$id reads a custom-named title property', async ({ title }) => {
61+
await expect(title()).resolves.toBe(PAGE_TITLE)
62+
})
63+
})

apps/sim/tools/notion/update_page.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionResponse, NotionUpdatePageParams } from '@/tools/notion/types'
22
import { PAGE_OUTPUT_PROPERTIES } from '@/tools/notion/types'
3+
import { extractTitle } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
export const notionUpdatePageTool: ToolConfig<NotionUpdatePageParams, NotionResponse> = {
@@ -57,19 +58,7 @@ export const notionUpdatePageTool: ToolConfig<NotionUpdatePageParams, NotionResp
5758

5859
transformResponse: async (response: Response) => {
5960
const data = await response.json()
60-
let pageTitle = 'Untitled'
61-
62-
// Try to extract the title from properties
63-
if (data.properties?.title) {
64-
const titleProperty = data.properties.title
65-
if (
66-
titleProperty.title &&
67-
Array.isArray(titleProperty.title) &&
68-
titleProperty.title.length > 0
69-
) {
70-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
71-
}
72-
}
61+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
7362

7463
return {
7564
success: true,
@@ -133,18 +122,7 @@ export const notionUpdatePageV2Tool: ToolConfig<
133122

134123
transformResponse: async (response: Response) => {
135124
const data = await response.json()
136-
let pageTitle = 'Untitled'
137-
138-
if (data.properties?.title) {
139-
const titleProperty = data.properties.title
140-
if (
141-
titleProperty.title &&
142-
Array.isArray(titleProperty.title) &&
143-
titleProperty.title.length > 0
144-
) {
145-
pageTitle = titleProperty.title.map((t: any) => t.plain_text || '').join('')
146-
}
147-
}
125+
const pageTitle = extractTitle(data.properties ?? {}) || 'Untitled'
148126

149127
return {
150128
success: true,

0 commit comments

Comments
 (0)