DEV Community

JOHNATAN STEVEN ORTIZ SALAZAR
JOHNATAN STEVEN ORTIZ SALAZAR

Posted on • Updated on • Originally published at johnatanortiz.tech

How to unlock the limitations of Notion

Notion rich_text limitations - node client

Notion has undoubtedly gained popularity as a versatile productivity and organization platform. Its ability to create documents, databases, boards, and more, all in one place, has attracted a wide range of users, from students to business professionals. However, like any tool, Notion also has its limitations, especially when it comes to its API and handling rich_text.

What is rich_text in Notion?

Before diving into the limitations, it's essential to understand what rich_text in Notion is exactly. In simple terms, rich_text refers to the rich text formatting that can be used within Notion. This includes styles such as bold, italic, strikethrough, numbered and bulleted lists, as well as links and mentions to other pages.

What are the principal limitation

One of the primary limitations of the Notion API is its restriction on the maximum number of characters that can be processed in a single request. Presently, the Notion API accepts a maximum of 2000 characters per request. This constraint poses a significant challenge for developers working with large bodies of text or intricate data structures within the Notion platform.

Property value type Inner property Size limit
https://developers.notion.com/reference/rich-text text.content 2000 characters
https://developers.notion.com/reference/rich-text text.link.url 2000 characters
https://developers.notion.com/reference/rich-text equation.expression 1000 characters

Solution for mitigate the notion API limits

The most effective solution for mitigating the limitations imposed by the Notion API's character restriction is to segment the content into smaller chunks of 2000 characters or less. By breaking down the text content into manageable chunks.

Example:

  • This is the typical way a page would be added:
const page = await notion.pages.create({

parent: { database_id: databaseId },
      properties: {
        nameOfColumn: {
          rich_text: [
            {
              type: 'text',
              text: {
                content: 'This is a long text...'
              }
            }
          ]
       },
    }
});
Enter fullscreen mode Exit fullscreen mode
  • This is the way that we need to insert the page with the long text inside
function splitTextIntoChunks(text: string, chunkSize: number) {
  const chunks = [];
  for (let i = 0; i < text.length; i += chunkSize) {
    chunks.push(text.slice(i, i + chunkSize));
  }
  return chunks;
}

const chunks = splitTextIntoChunks('This is a long text...', 2000);

const page = await notion.pages.create({

parent: { database_id: databaseId },
      properties: {
        nameOfColumn: {
         rich_text: chunks.map(chunk => ({
            type: 'text',
            text: {
              content: chunk
            }
          }))
       },
    }
});
Enter fullscreen mode Exit fullscreen mode

Implementing this approach ensures efficient data transmission within the constraints of the Notion API, facilitating seamless integration and manipulation of content.

Top comments (0)