FunctionThe options for creating a page.
The data for creating the page.
The parent of the page (must include data_source_id, page_id, or database_id (database_id is deprecated and will not work in databases with more than one data source)).
Optionalproperties?: ObjectThe properties of the page.
Optionalicon?: ObjectThe icon of the page.
Optionalcover?: ObjectThe cover of the page.
Optionalchildren?: Object[]An array of child blocks to add to the page.
Optionalclient?: ObjectThe Notion client object. Either this or apiCall must be provided.
OptionalapiCall?: FunctionA custom function for making API calls. Receives { type: 'create_page', data } as argument. Either this or client must be provided.
OptionalgetPage?: FunctionA function to extract the page data from the API response. Defaults to (response) => response.
OptionalgetResults?: FunctionA function to extract results from the API response when appending blocks. Defaults to (response) => response.results.
OptionaltemplateWaitMs?: numberMilliseconds to wait after page creation when using templates, before appending children.
OptionalonTemplatePageCreated?: FunctionOptional callback function called after page creation but before appending children when using templates. Receives { page, template, fallbackWaitMs } as parameter, where page is the created Notion page object, template is the template object used to create the page, and fallbackWaitMs is the value of templateWaitMs. Can throw an error to stop execution and prevent children appending. Alternatively, you can pass a number to templateWaitMs, which the callback can use in case it fails to directly verify the template is ready.
OptionalskipAutoAppendOnTemplate?: booleanIf true, returns children to caller instead of auto-appending them when using templates.
An object containing the API response for page creation and, if applicable, the result of appending children. When skipAutoAppendOnTemplate is true and templates are used, returns { apiResponse, pendingChildren, pageId } instead.
// Using with Notion SDK client
const notion = new Client({ auth: NOTION_TOKEN });
const page = createNotion()
.parentDataSource("your-data-source-id")
.title("Name", "Charmander")
.icon("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/4.png")
.richText("Category", "Lizard Pokémon")
.quote("Obviously prefers hot places. When it rains, steam is said to spout from the tip of its tail.")
.build()
const result = await createPage({
data: page.content,
client: notion
});
// Using with custom API call function
const apiCall = async ({ type, data }) => {
if (type === 'create_page') {
// Your custom API call implementation for page creation
return await someHTTPClient.post('https://api.notion.com/v1/pages', { json: data });
} else if (type === 'append_blocks') {
// Your custom API call implementation for block appending
const { block_id, children, after } = data;
return await someHTTPClient.patch(`https://api.notion.com/v1/blocks/${block_id}/children`, {
json: { children, ...(after && { after }) }
});
}
};
const result = await createPage({
data: page.content,
apiCall,
getPage: (response) => response,
getResults: (response) => response.results
});
Creates a new page in Notion and optionally appends child blocks to it.