1 | |
2 |
|
3 | |
4 | * Update Page Properties |
5 | * Set a page's title, icon, or property values. `properties` takes Notion property values keyed by name, e.g. {"Status": {"status": {"name": "Done"}}}; properties left out are unchanged. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Notion, |
9 | page_id: string, |
10 | title: string | undefined, |
11 | properties: { [key: string]: any } | undefined, |
12 | icon_emoji: string | undefined |
13 | ) { |
14 | const body: { [key: string]: any } = { properties: { ...properties } } |
15 | if (title !== undefined && title !== "") { |
16 | body.properties.title = { title: [{ text: { content: title } }] } |
17 | } |
18 | if (icon_emoji !== undefined && icon_emoji !== "") { |
19 | body.icon = { type: "emoji", emoji: icon_emoji } |
20 | } |
21 |
|
22 | const response = await fetch(`https://api.notion.com/v1/pages/${page_id}`, { |
23 | method: "PATCH", |
24 | headers: { |
25 | Authorization: `Bearer ${auth.token}`, |
26 | "Content-Type": "application/json", |
27 | Accept: "application/json", |
28 | "Notion-Version": "2026-03-11", |
29 | }, |
30 | body: JSON.stringify(body), |
31 | }) |
32 |
|
33 | if (!response.ok) { |
34 | throw new Error(`${response.status} ${await response.text()}`) |
35 | } |
36 |
|
37 | return await response.json() |
38 | } |
39 |
|