An util that help users operate their
notionapi-agent
and convert a Notion page to a Notion Abstract Syntax Tree (NotionAST).The library is currently a Work In Progress, so it may be unstable.
The library is unofficial.
This is a Node.js module. You can install in your project.
npm i notionast-util-from-notionapi --save
You also need notionapi-agent
.
npm i notionapi-agent --save
The agent is used to retrieve raw data from Notion's API /api/v3/getRecordValues
.
const fs = require('fs')
const NotionAgent = require('notionapi-agent')
const downloadPageAsTree = require('notionast-util-from-notionapi')
/* Fill in your token. */
const options = {
token: ''
}
const agent = new NotionAgent(options)
async function main() {
try {
/* Fill in a page ID. */
let pageID = ''
let tree = await downloadPageAsTree(pageID, agent)
let file = `PageTree-${pageID}.json`
fs.writeFileSync(file, JSON.stringify(tree), { encoding: 'utf-8' })
} catch (error) {
console.error(error)
}
}
main()
Download a Notion page as a Notion Abstract Syntax Tree with a Notion API agent.
-
pageID
- (required) The ID of a Notion page. Must be the one with dashes. e.g.'cbf2b645-xxxx-xxxx-xxxx-xxxxe8cfed93'
-
agent
- (required) An API agent with methodgetRecordValues
. I recomment using notionapi-agent.
A Notion Abstract Syntax Tree. Refer to src/types/api-lagacy.ts
for details.
interface BlockNode {
id: string
type: string
data?: BlockProperties
raw_value: BlockValue
children: BlockNode[]
}
- Notion has somewhat messed up with their data structure recently.
BlockNode.raw_value.parent_id
is incorrect for some blocks.