Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions examples/pages/move-page/index.js
Original file line number Diff line number Diff line change
@@ -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);
})();
3 changes: 1 addition & 2 deletions examples/shared/notion-api.js
Original file line number Diff line number Diff line change
@@ -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}`,
Expand Down