From d2e7a7dd26414044e56a96c380bba1b24fdfb09a Mon Sep 17 00:00:00 2001 From: Benjamin Borowski Date: Mon, 17 Nov 2025 16:35:16 -0800 Subject: [PATCH] Move page examples --- examples/pages/move-page/index.js | 67 +++++++++++++++++++++++++++++++ examples/shared/notion-api.js | 3 +- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 examples/pages/move-page/index.js diff --git a/examples/pages/move-page/index.js b/examples/pages/move-page/index.js new file mode 100644 index 0000000..052f68e --- /dev/null +++ b/examples/pages/move-page/index.js @@ -0,0 +1,67 @@ +/** + * Arguments: + * + * --page-id (-p): ID of the page to move + * --target-page-id (-t): ID of the page to move to + * --target-data-source-id (-d): ID of the data source to move to + */ + +const { notion, yargs } = require('../../shared'); +// TODO: Swap for ^ when available in javascript SDK +const notionAPI = require('../../shared/notion-api'); +const { log } = require('../../shared/utils'); + +// 2af1c1cce3f3802985bdecfa26194f94 (page) +// 2ae1c1cce3f3815a8140ce2cac1a27b8 (target page) +// 1cf71d9401074560a702a41cb5d90aea (target data source) + +const argv = yargs + .option('pageId', { + alias: 'p', + describe: 'The ID of the block to move', + demand: true, + }) + .option('targetPageId', { + alias: 't', + describe: 'The ID of the page to move the selected block to', + }) + .option('targetDataSourceId', { + alias: 'd', + describe: 'The ID of the data source to move the selected block to', + }).argv; + +(async () => { + let page = await notion.pages.retrieve({ + page_id: argv.pageId, + }); + + let type; + let target; + + // Find the target + if (argv.targetPageId) { + type = 'page_id'; + target = await notion.pages.retrieve({ + page_id: argv.targetPageId, + }); + } else { + type = 'data_source_id'; + target = await notion.dataSources.retrieve({ + data_source_id: argv.targetDataSourceId, + }); + } + + // Move the block + // SEE: https://developers.notion.com/reference/move-page + + const response = await notionAPI.post(`/pages/${page.id}/move`, { + parent: { + type, + [type]: target.id, + }, + }); + + page = response.data; + + log(page); +})(); diff --git a/examples/shared/notion-api.js b/examples/shared/notion-api.js index a70eaae..87e535a 100644 --- a/examples/shared/notion-api.js +++ b/examples/shared/notion-api.js @@ -1,9 +1,8 @@ - const { default: axios } = require('axios'); const dotenv = require('dotenv'); dotenv.config(); -const NOTION_VERSION = '2025-09-03' +const NOTION_VERSION = '2025-09-03'; const NOTION_HEADERS = { Authorization: `Bearer ${process.env.NOTION_API_TOKEN}`,