Skip to content

Latest commit

 

History

History
63 lines (39 loc) · 2.84 KB

File metadata and controls

63 lines (39 loc) · 2.84 KB

Sample integration: Parse text from any block type

Parse plain text from any type of block (i.e. page content), including headers, lists, media, etc.

About the integration

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.

About page content

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.

Running Locally

1. Setup your local project

# 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 install

2. Set your environment variables in a .env file

A .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. A Notion page URL with the ID highlighted

3. Give the integration access to your page

Your Notion integration will need permission to retrieve the block children from the Notion page being used. To provide access, do the following:

  1. Go to the page in your workspace.
  2. Click the ••• (more menu) on the top-right corner of the page.
  3. Scroll to the bottom of the menu and click Add connections.
  4. 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.

4. Run code

npm start