How to unlock the limitations of Notion

johnatan_stevenortizsal

JOHNATAN STEVEN ORTIZ SALAZAR

Posted on June 5, 2024

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.

💖 💪 🙅 🚩
johnatan_stevenortizsal
JOHNATAN STEVEN ORTIZ SALAZAR

Posted on June 5, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024