1.1.28
Object with methods to construct the majority of block types supported by the Notion API.
Block types include bookmark, bulleted list item, callout, code, divider, embed, file, heading, image, numbered list item, paragraph, pdf, quote, table, table row, table of contents, to-do, toggle, and video. Some block types return null if they are provided with invalid data; you should filter these out your final children array.
Not implemented: Breadcrumb, column list, column, equation, link preview (unsupported), mention, synced block (unsupported)
Methods for bookmark blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a bookmark block.
Object
:
A bookmark block object compatible with Notion's API.
// Use with just a URL
const simpleBookmark = block.bookmark.createBlock("https://www.flylighter.com");
// Use with options object
const complexBookmark = block.bookmark.createBlock({
url: "https://www.flylighter.com",
caption: "Flylighter is a super-rad web clipper for Notion."
});
// Use with options object and array of strings for caption
const multiLineBookmark = block.bookmark.createBlock({
url: "https://www.flylighter.com",
caption: ["Flylighter is a web clipper for Notion...", "...and Obsidian, too."]
});
Methods for bulleted list item blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a bulleted list item block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the list item content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the text. |
Object
:
A bulleted list item block object compatible with Notion's API.
// Use with a string
const simpleItem = block.bulleted_list_item.createBlock("Simple list item");
// Use with an array of strings
const multiLineItem = block.bulleted_list_item.createBlock(["Line 1", "Line 2"]);
// Use with options object
const complexItem = block.bulleted_list_item.createBlock({
content: "Complex item",
color: "red",
children: [
// Child blocks would go here
]
});
Methods for callout blocks.
Creates a callout block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the callout content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.icon string
(default "" )
|
An optional icon value (URL for "external" or emoji character for "emoji"). |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the callout background. |
Object
:
A callout block object compatible with Notion's API.
// Use with a string
const simpleCallout = block.callout.createBlock("I though I told you never to come in here, McFly!");
// Use with options object
const complexCallout = block.callout.createBlock({
content: "Now make like a tree and get outta here.",
icon: "💡",
color: "blue_background",
children: [
// Child blocks would go here
]
});
Methods for code blocks.
Creates a code block.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The code content as a string, an array of strings, or an array of rich text objects. |
options.caption (string | Array<string> | Array<Object>)
(default [] )
|
The caption as a string, an array of strings, or an array of rich text objects. |
options.language string
(default "plain text" )
|
Programming language of the code block. |
Object
:
A code block object compatible with Notion's API.
// Use with a string
const simpleCode = block.code.createBlock("console.log('Give me all the bacon and eggs you have.');");
// Use with options object
const complexCode = block.code.createBlock({
content: "const name = 'Monkey D. Luffy'\n console.log(`My name is ${name} and I will be king of the pirates!`)",
language: "JavaScript",
caption: "A simple JavaScript greeting function"
});
Methods for divider blocks.
(boolean)
: Indicates if the block supports child blocks.
Methods for embed blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates an embed block.
Object
:
An embed block object compatible with Notion's API.
// Use with a string
const simpleEmbed = block.embed.createBlock("https://www.youtube.com/watch?v=ec5m6t77eYM");
// Use with options object
const complexEmbed = block.embed.createBlock({
url: "https://www.youtube.com/watch?v=ec5m6t77eYM"
});
Methods for file blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a file block.
(Object | null)
:
A file block object compatible with Notion's API, or null if the URL is invalid.
// Use with a string
const simpleFile = block.file.createBlock("https://collegeinfogeek.com/wp-content/uploads/2015/01/10steps-reddit.pdf");
// Use with options object
const complexFile = block.file.createBlock({
url: "https://collegeinfogeek.com/wp-content/uploads/2015/01/10steps-reddit.pdf",
name: "10 Steps to Earning Awesome Grades (preview)",
caption: "The Reddit preview of the 10 Steps to Earning Awesome Grades book."
});
Methods for heading_1 blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a heading_1 block.
Adding children will coerce headings to toggle headings.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the heading content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.color string
(default "default" )
|
Color for the heading text. |
options.is_toggleable boolean
(default false )
|
Whether the heading is toggleable. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
Object
:
A heading_1 block object compatible with Notion's API.
// Use with a string
const simpleHeading = block.heading_1.createBlock("Simple Heading");
// Use with options object
const complexHeading = block.heading_1.createBlock({
content: "Complex Heading",
color: "red",
is_toggleable: true,
children: [
// Child blocks would go here
]
});
Methods for heading_2 blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a heading_2 block.
Adding children will coerce headings to toggle headings.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the heading content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.color string
(default "default" )
|
Color for the heading text. |
options.is_toggleable boolean
(default false )
|
Whether the heading is toggleable. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
Object
:
A heading_2 block object compatible with Notion's API.
// Use with a string
const simpleHeading = block.heading_2.createBlock("Simple Heading");
// Use with options object
const complexHeading = block.heading_2.createBlock({
content: "Complex Heading",
color: "red",
is_toggleable: true,
children: [
// Child blocks would go here
]
});
Methods for heading_3 blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a heading_3 block.
Adding children will coerce headings to toggle headings.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the heading content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.color string
(default "default" )
|
Color for the heading text. |
options.is_toggleable boolean
(default false )
|
Whether the heading is toggleable. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
Object
:
A heading_3 block object compatible with Notion's API.
// Use with a string
const simpleHeading = block.heading_3.createBlock("Simple Heading");
// Use with options object
const complexHeading = block.heading_3.createBlock({
content: "Complex Heading",
color: "red",
is_toggleable: true,
children: [
// Child blocks would go here
]
});
Methods for image blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates an image block.
(Object | null)
:
An image block object compatible with Notion's API, or null if the URL is invalid.
// Use with a string
const simpleImage = block.image.createBlock("https://i.imgur.com/5vSShIw.jpeg");
// Use with options object
const complexImage = block.image.createBlock({
url: "https://i.imgur.com/5vSShIw.jpeg",
caption: "A beautiful landscape"
});
Methods for numbered list item blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a numbered list item block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the list item content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the text. |
Object
:
A numbered list item block object compatible with Notion's API.
// Use with a string
const simpleItem = block.numbered_list_item.createBlock("Simple list item");
// Use with an array of strings
const multiLineItem = block.numbered_list_item.createBlock(["Line 1", "Line 2"]);
// Use with options object
const complexItem = block.numbered_list_item.createBlock({
content: "Complex item",
color: "red",
children: [
// Child blocks would go here
]
});
Methods for paragraph blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a paragraph block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the paragraph content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the text. |
Object
:
A paragraph block object compatible with Notion's API.
// Direct use with a string
const paragraphBlock = block.paragraph.createBlock("Hello, World!");
// Direct use with an array of strings
const multiLineParagraph = block.paragraph.createBlock(["I'm a line", "I'm also a line!"]);
// Usage with options object
const complexParagraph = block.paragraph.createBlock({
content: "Complex paragraph",
color: "red",
children: [
// Child blocks would go here
]
});
Methods for PDF blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a PDF block.
(Object | null)
:
A PDF block object compatible with Notion's API, or null if the URL is invalid.
// Use with a string
const simplePDF = block.pdf.createBlock("https://collegeinfogeek.com/wp-content/uploads/2015/01/10steps-reddit.pdf");
// Use with options object
const complexPDF = block.pdf.createBlock({
url: "https://collegeinfogeek.com/wp-content/uploads/2015/01/10steps-reddit.pdf",
caption: "The Reddit preview of the 10 Steps to Earning Awesome Grades book."
});
Methods for quote blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a quote block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the quote content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the text. |
Object
:
A quote block object compatible with Notion's API.
// Use with a string
const simpleQuote = block.quote.createBlock("Simple quote");
// Use with an array of strings
const multiLineQuote = block.quote.createBlock(["Line 1 of quote", "Line 2 of quote"]);
// Use with options object
const complexQuote = block.quote.createBlock({
content: "Complex quote",
color: "gray",
children: [
// Child blocks would go here
]
});
Methods for table blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a table block.
(Object)
Options for creating the table.
Name | Description |
---|---|
options.has_column_header boolean
(default false )
|
Whether the table has a column header. |
options.has_row_header boolean
(default false )
|
Whether the table has a row header. |
options.rows (Array<Array<string>> | Array<Object>)
(default [] )
|
An array of rows. Each row can be an array of strings or a table_row object. |
Object
:
A table block object compatible with Notion's API.
// Use with array of string arrays
const simpleTable = block.table.createBlock({
rows: [
["Header 1", "Header 2"],
["Row 1, Cell 1", "Row 1, Cell 2"],
["Row 2, Cell 1", "Row 2, Cell 2"]
],
has_column_header: true
});
// Use with array of table_row objects
const complexTable = block.table.createBlock({
rows: [
block.table_row.createBlock(["Header 1", "Header 2"]),
block.table_row.createBlock(["Row 1, Cell 1", "Row 1, Cell 2"]),
block.table_row.createBlock(["Row 2, Cell 1", "Row 2, Cell 2"])
],
has_column_header: true,
has_row_header: false
});
Methods for table row blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a table row block.
Object
:
A table row block object compatible with Notion's API.
// Use with an array of strings
const simpleRow = block.table_row.createBlock(["Cell 1", "Cell 2", "Cell 3"]);
// Use with an array of rich text objects
const complexRow = block.table_row.createBlock([
[{ type: "text", text: { content: "Cell 1" } }],
[{ type: "text", text: { content: "Cell 2", annotations: { bold: true } } }],
[{ type: "text", text: { content: "Cell 3" } }]
]);
Methods for table of contents blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a table of contents block.
Object
:
A table of contents block object compatible with Notion's API.
// Use with default settings
const simpleTOC = block.table_of_contents.createBlock();
// Use with a color string
const coloredTOC = block.table_of_contents.createBlock("red");
// Use with options object
const complexTOC = block.table_of_contents.createBlock({ color: "blue" });
Methods for to-do list blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a to-do list block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the to-do content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.checked boolean
(default false )
|
Whether the to-do item is checked. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the to-do text. |
Object
:
A to-do list block object compatible with Notion's API.
// Use with a string
const simpleToDo = block.to_do.createBlock("Simple task");
// Use with options object
const complexToDo = block.to_do.createBlock({
content: "Complex task",
checked: true,
color: "green",
children: [
// Child blocks would go here
]
});
Methods for toggle blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a toggle block.
((string | Array<string> | Object))
A string, an array of strings, or an options object representing the toggle content.
Name | Description |
---|---|
options.content (string | Array<string> | Array<Object>)
(default [] )
|
The content as a string, an array of strings, or an array of rich text objects. |
options.children Array<Object>
(default [] )
|
An array of child block objects. |
options.color string
(default "default" )
|
Color for the toggle text. |
Object
:
A toggle block object compatible with Notion's API.
// Use with a string
const simpleToggle = block.toggle.createBlock("Simple toggle");
// Use with options object
const complexToggle = block.toggle.createBlock({
content: "Complex toggle",
color: "blue",
children: [
// Child blocks would go here
]
});
Methods for video blocks.
(boolean)
: Indicates if the block supports child blocks.
Creates a video block.
(Object | null)
:
A video block object compatible with Notion's API, or null if the URL is invalid.
// Use with a string
const simpleVideo = block.video.createBlock("https://www.youtube.com/watch?v=ec5m6t77eYM");
// Use with options object
const complexVideo = block.video.createBlock({
url: "https://www.youtube.com/watch?v=ec5m6t77eYM",
caption: "Never gonna give you up"
});
Block shorthand methods – these allow you to call the createBlock() method for the properties of the block object more quickly. Import them directly into a file, or call them on NotionHelper.
Creates a bulleted list item block.
Object
:
A bulleted list item block.
Shorthand alias for bulletedListItem(). Creates a bulleted list item block.
Object
:
A bulleted list item block.
Creates a callout block.
Object
:
A callout block.
Creates a heading_1 block.
Object
:
A heading_1 block.
Creates a heading_2 block.
Object
:
A heading_2 block.
Creates a heading_3 block.
Object
:
A heading_3 block.
Creates a numbered list item block.
Object
:
A numbered list item block.
Shorthand alias function for numberedListItem(). Creates a numbered list item block.
Object
:
A numbered list item block.
Creates a paragraph block.
Object
:
A paragraph block.
Creates a quote block.
Object
:
A quote block.
Creates a table of contents block.
Object
:
A table of contents block.
Creates a to-do list block.
Object
:
A to-do list block.
Creates a toggle block.
Object
:
A toggle block.
Simple function to create standard Paragraph blocks from an array of strings without any special formatting. Each Paragraph block will contain a single Rich Text Object.
Array<Object>
:
array of Paragraph blocks.
(string)
either an emoji character or a URL for an externally-hosted image file.
Object
:
An object representing the icon.
Creates a representation of an external link.
(string)
The URL of the external link.
Object
:
An object containing the external URL.
Creates a representation of an emoji.
(string)
The emoji character.
Object
:
An object containing the emoji.
Creates a representation of a file link.
(string)
The URL of the file.
Object
:
An object containing the file URL.
Object with methods for constructing Notion page metadata, including parent, page, block, property, cover, and icon.
Parent creates a parent object. Page, block, and property create ID objects. Cover creates an external image object, while icon can create an external image object or an emoji object.
Metadata definition for a page ID property.
(string)
: The data type the property accepts.
Metadata definition for a block ID property.
(string)
: The data type the property accepts.
Metadata definition for a property ID property.
(string)
: The data type the property accepts.
Metadata definition for an icon.
(string)
: The data type the property accepts.
Page shorthand methods - these allow you to call the createMeta() method for the properties of the page_meta object more quickly. Import them directly into a file, or call them on NotionHelper.
Object with methods for constructing each of the possible property types within a Notion database page.
Property types include title, rich_text, checkbox, date, email, files, multi_select, number, people, phone_number, relation, select, status, and url.
Methods for title properties.
(string)
: The data type the property accepts.
Sets a title property's value.
Object
:
A title property object.
Notion API will throw an error if title doesn't contain an array of Rich Text object(s) (RTOs). setProp() will convert a string, or array of strings, to an array of Rich Text object(s). On other invalid input, it will throw an error.
Methods for rich text properties.
(string)
: The data type the property accepts.
Methods for checkbox properties.
(string)
: The data type the property accepts.
Methods for date properties.
(string)
: The data type the property accepts.
Methods for email properties.
(string)
: The data type the property accepts.
Methods for multi_select properties.
(string)
: The data type the property accepts.
Methods for number properties.
(string)
: The data type the property accepts.
Methods for people properties.
(string)
: The data type the property accepts.
Methods for phone_number properties.
(string)
: The data type the property accepts.
Methods for relation properties.
(string)
: The data type the property accepts.
Methods for select properties.
(string)
: The data type the property accepts.
Methods for status properties.
(string)
: The data type the property accepts.
Property shorthand methods - these allow you to call the setProp() method for the properties of the page_props object more quickly. Import them directly into a file, or call them on NotionHelper.
Validates values passed to the setProp() methods above. Performs some transformation in certain cases.
(any)
the value being passed to setProp(), which invokes this function
(string)
the type of value expected by this Notion API property
(Object)
Name | Description |
---|---|
$0.parent any
|
|
$0.parent_type any
|
|
$0.pages any
|
|
$0.schema any
|
|
$0.childrenFn any
|
(Object)
(string)
The ID of the parent page or database.
(string)
"page_id" or "database_id".
((Array<Object> | Object))
an array of simple objects, each of which will be turned into a valid page object. Each can have property types that match to valid Notion page properties, as well as a "cover", "icon", and "children" property. The "children" prop's value should be either a string or an array. You can also pass a single object, but the function will still return an array.
(Object)
an object that maps the schema of the pages objects to property names and types in the parent. Saves you from needing to specify the property name and type from the target Notion database for every entry in your pages object. For each property in your pages object that should map to a Notion database property, specify the key as the property name in the pages object and set the value as an array with the Notion property name as the first element and the property type as the second. Non-valid property types will be filtered out. Optionall, you can specify custom keys for the icon (["Icon", "icon"]), cover (["Cover", "cover"]), and children array (["Children", "children"]).
(function)
a callback you can specify that will run on any array elements present in a "children" property of any object in the pages array. If that "children" property contains a single string, it'll run on that as well. If omitted, any "children" values will be converted to Paragraph blocks by default.
Array<Object>
:
An array of page objects, each of which can be directly passed as the children for a POST request to
https://api.notion.com/v1/pages
(or as the single argument to notion.pages.create() when using the SDK).
const database = "abcdefghijklmnopqrstuvwxyz"
const tasks = [ {
icon: "😛",
task: "Build Standing Desk",
due: "2024-09-10",
status: "Not started"
} ]
const schema = {
task: [ "Name", "title" ],
due: [ "Due Date", "date"],
status: [ "Status", "status" ]
}
const pageObjects = quickPages({
parent: database,
parent_type: "database_id",
pages: tasks,
schema: schema,
childrenFn: (value) => NotionHelper.makeParagraphs(value)
})
A builder object for Notion content.
Type: Object
A factory function that provides methods for building Notion objects, including pages, properties, and blocks. It adds an unhealthily-large spoonful of syntactic sugar onto the Notion API.
Returns an object with two possible properties:
content (always returned) - can be a full page object, an array of blocks, or a properties object.
addititionalBlocks - array containing arrays of blocks passed to the builder function that go over Notion's limit for the number of blocks that can be in a children array. This allows you to add these to the returned page or block in further requests.
This builder supports chaining methods so you can build pages or structures incrementally. It also supports block-nesting with the startParent() and endParent() methods.
After adding all your blocks and properties, call build() to return the final object. It can be passed directly as the data object in Notion API requests.
NotionBuilder
:
A builder object with methods for constructing and managing Notion content. The builder includes methods to set page and property details, add various block types, manage nested structures, and ultimately build Notion-compatible objects.
const notionBuilder = createNotion();
// Build a new Notion page with various blocks
const result = notionBuilder
.parentDb('database-id')
.title('Page Title', 'Hello World')
.paragraph('This is the first paragraph.')
.heading1('Main Heading')
.build();
// Access the built content and handle additional blocks if they exist
console.log(result.content); // The main Notion page content
console.log(result.additionalBlocks); // Any blocks that need separate requests due to size constraints
// Create a page in Notion with the result (assumes you've installed and imported the Notion SDK and instantiated a client bound to a 'notion' variable)
const response = await notion.pages.create(result.content)
Type: NotionBuilder
Sets a files property value for the page.
NOTE: The separate file() method creates a file block.
this
:
The builder instance for method chaining.
Starts a new parent block that can contain child blocks.
(string)
The type of block to create as a parent.
(Object
= {}
)
Options for creating the block, specific to the block type.
this
:
The builder instance for method chaining.
notion.startParent('toggle', 'Click to expand')
.paragraph('This is inside the toggle')
.endParent();
Ends the current parent block and moves up one level in the block hierarchy.
this
:
The builder instance for method chaining.
notion.startParent('toggle', 'Click to expand')
.paragraph('This is inside the toggle')
.endParent();
Adds a new block to the current level in the block hierarchy.
(string)
The type of block to add.
(Object
= {}
)
Options for creating the block, specific to the block type.
this
:
The builder instance for method chaining.
notion.addBlock('paragraph', 'This is a paragraph.');
// Or using the shorthand method:
notion.paragraph('This is a paragraph.');
Adds a paragraph block to the current stack. If this method recieves a string over the max character length, it will split it and add multiple paragraph blocks to the stack. This differs from the other block methods, which will instead split long strings into an array of multiple rich_text objects.
If you prefer that behavior for paragraphs, you can import enforceStringLength() yourself, run your string through it, then pass the returned array to this method.
(any)
this
:
The builder instance for method chaining.
Adds a heading_1 block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a heading_2 block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a heading_3 block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a bulleted_list_item block to the current stack.
(any)
this
:
The builder instance for method chaining.
Shorthand alias for bulletedListItem(). Adds a bulleted_list_item block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a numbered_list_item block to the current stack.
(any)
this
:
The builder instance for method chaining.
Shorthand alias for numberedListItem(). Added a numbered_list_item block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a to_do block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a toggle block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a code block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a quote block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a callout block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a divider block to the current stack.
this
:
The builder instance for method chaining.
Adds an image block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a video block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a file block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a pdf block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a bookmark block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds an embed block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a table_of_contents block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a table block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a table_row block to the current stack.
(any)
this
:
The builder instance for method chaining.
Adds a block to the stack for each element in the passed array.
(any)
(any)
this
:
The builder instance for method chaining.
Builds and returns the final Notion object based on the current state of the builder.
((Object | Array))
: The main content of the built object. This can be a full page object, a properties object, or an array of blocks, depending on what was added to the builder.
(Array)
: Any blocks that exceed Notion's maximum block limit per request. These will need to be added in subsequent requests.
this
:
An object containing the built content and any additional blocks.
const notion = createNotion();
const result = notion
.dbId('your-database-id')
.title('Page Title', 'My New Page')
.paragraph('This is a paragraph.')
.build();
console.log(result.content); // The main page content
console.log(result.additionalBlocks); // Any blocks that couldn't fit in the initial request
Resets the builder to its initial state, clearing all added content.
this
:
The builder instance for method chaining.
const notion = createNotion();
notion
.dbId('your-database-id')
.title('Page Title', 'My New Page')
.paragraph('This is a paragraph.')
.build();
// Reset the builder for a new page
notion.reset()
.dbId('another-database-id')
.title('Page Title', 'Another New Page')
.build();
Builds a Rich Text Object. See: https://developers.notion.com/reference/rich-text
(any
= {}
)
(string)
The URL for this object, if any. Creates a clickable link.
(string
= text
)
An optional type for the Rich Text Object. Supports text, equation, and mention.
(Object)
Options for the Annotation object.
Name | Description |
---|---|
opts.bold boolean
|
Bold text |
opts.italic boolean
|
Italic text |
opts.strikethrough boolean
|
Strikethrough text |
opts.underline boolean
|
Underlined text |
opts.code boolean
|
Code-style text |
opts.color string
|
String specifying the text's color or background color. Opts: "blue", "brown", "default", "gray", "green", "orange", "pink", "purple", "red", "yellow". All except "default" can also be used as a background color with "[color]_background" - example: "blue_background". See: https://developers.notion.com/reference/rich-text#the-annotation-object |
Array<Object>
:
Array with a single Rich Text Object
Enforces Rich Text format for content.
Array
:
An array of Rich Text Objects.
Enforces a single Rich Text Object format.
Object
:
A Rich Text Object.
Checks if a string contains only a single emoji.
(string)
boolean
:
Checks if a string is a valid URL.
(string)
boolean
:
Checks if an image URL is both a valid URL and has a supported image file type.
(url)
the URL to be checked
boolean
:
Checks if a video URL is both a valid URL and will be accepted by the API, based on a list of supported file extensions and embed websites.
(url)
the URL to be checked
boolean
:
Checks if a PDF URL is both a valid URL and ends with the .pdf extension.
(url)
the URL to be checked
boolean
:
Enforces a length limit on a string. Returns the original string in a single-element array if it is under the limit. If not, returns an array with string chunks under the limit.
Array<string>
:
array with the original string, or chunks of the string if it was over the limit.
Validates Date object or string input that represents a date, and converts it to an ISO-8601 date string if possible.
string
: