Power tools for the Notion API
notion-helper is a Node.js library that makes working with the Notion API a breeze.
Easy to learn, zero dependencies, open-source, full JSDoc for IntelliSense.
Built by Thomas Frank.
Let's say you've got a JSON object that you want to turn into a page in a Notion database.
notion-helper's createNotion()
function allows you to build page objects with far less code.
It'll create multiple blocks from an array with loop()
, handle date strings for you, and a lot more.
With notion-helper:
Without notion-helper:
createNotion()
has other tricks up its sleeve, too…
Add child blocks to any supported block by defining it with startParent()
. This lets you build tables!
Pass a callback to loop()
instead of a block type to define custom handling.
P.S. – See the number in that tracks
object? Normally, the API will pitch a fit if you try to put that in a table cell. But notion-helper will just coerce it to a string for you. 🧶
The Notion API only supports 100 blocks in any block array sent in a single request.
createNotion()
returns an additionalBlocks
property with additional block chunks. Loop over this with Append Block Children calls to build pages with hundreds or thousands of blocks.
createNotion()
can build full page objects, or it can go more granular and return a property
object or an array of blocks you can use in a children
property.
Simply add parentDb()
, parentPage()
, pageId()
, or blockId()
to the chain to create a page/block object.
Add only property methods to return a property
object. (Examples: title()
, richText()
, relation()
, date()
…)
Add only block methods to return an array of blocks. (Examples: heading1()
, paragraph()
, bulletListItem()
…)
createNotion()
includes methods for building/setting any kind of supported object, property, or block. It also includes some generic methods for fine-grained control.
Property Methods:
property(name, type, value)
title(name, value)
richText(name, value)
checkbox(name, value)
date(name, start, end)
email(name, value)
files(name, fileArray)
multiSelect(name, valuesArray)
number(name, value)
people(name, personArray)
phoneNumber(name, value)
relation(name, pageArray)
select(name, value)
status(name, value)
url(name, value)
Block Methods:
addBlock(blockType, options)
startParent(blockType, options)
endParent()
paragraph(options)
heading1(options)
heading2(options)
heading3(options)
bulletedListItem(options)
bullet(options)
- alias functionnumberedListItem(options)
num(options)
- alias functiontoDo(options)
toggle(options)
code(options)
quote(options)
callout(options)
divider()
image(options)
video(options)
file(options)
pdf(options)
bookmark(options)
embed(options)
tableOfContents(options)
table(options)
tableRow(options)
loop(blockTypeOrCallback, options)
Page/Block Object Methods:
parentDb()
parentPage()
pageId()
propertyId()
blockId()
cover()
icon()
Utility Methods:
build()
- creates the final object.reset()
- resets the builder.