Parse plain text from any type of block (i.e. page content), including headers, lists, media, etc.
This integration will retrieve Notion page content and parse any plain text from the block. (Note: page content is represented by blocks.) The plain text is printed to the command line in this example, but can be used in your Notion projects as needed.
When retrieving block children (i.e. page content) with the public API, the structure of the blocks returned will vary depending on the block type. For example, a paragraph block and an image block are modeled differently.
This example demonstrates how to parse any available text for any type of block. In many cases, rich text will be available and the plain_text value will be used.
Note: Not all blocks contain text to display (e.g. dividers). Additionally, not all block types are currently supported by the public API.
# Clone this repository locally
git clone https://github.com/makenotion/notion-cookbook.git
# Switch into this project
cd notion-cookbook/examples/parse-text-from-any-block-type
# Install the dependencies
npm installA .env.example file has been included and can be renamed .env. Update the environment variables below:
NOTION_API_KEY=<your-notion-api-key>
NOTION_PAGE_ID=<notion-page-id>NOTION_API_KEY: Create a new integration in the integrations dashboard and retrieve the API key from the integration's Secrets page.
NOTION_PAGE_ID: Use the ID of any Notion page with content. A page with a variety of block types is recommended.
The page ID is the 32 character string at the end of any page URL.

Your Notion integration will need permission to retrieve the block children from the Notion page being used. To provide access, do the following:
- Go to the page in your workspace.
- Click the
•••(more menu) on the top-right corner of the page. - Scroll to the bottom of the menu and click
Add connections. - Search for and select your integration in the
Search for connections...menu.
Once selected, your integration will have permission to read content from the page.
npm start