Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Notion rich_text[] max length is 100, markdownToBlocks() can create more than the limit #51

Open
roberttolton opened this issue Jun 6, 2023 · 3 comments

Comments

@roberttolton
Copy link

roberttolton commented Jun 6, 2023

Hi, thanks for this package!

I noted in the documentation that it should automatically try and spread data that would be too long into multiple blocks, however after using markdownToBlocks() with some data that contained many lines and line breaks, the result was a paragraph block with a rich_text array that had over 100 items, which is over Notion's API limit for rich_text items.

When reading the docs, I thought it might try and spread the excess rich_text items into other blocks, but looking at the source code it will either truncate the array or leave it as it is - I think we should create X-amount of blocks until all excess rich_text items can fit?

@roberttolton
Copy link
Author

Solution in my code for now:

// some code redacted
// import LIMITS
// chunk() is like a lodash chunk function

const blocks = markdownToBlocks(markdown)

blocks.forEach((block, blockIndex) => {

    if (
        block.type === 'paragraph' &&
        block.paragraph.rich_text.length > LIMITS.RICH_TEXT_ARRAYS
    ) {

        const newParagraphBlocks = []
        const richTextChunks = chunk(block.paragraph.rich_text, 100)

        richTextChunks.forEach(chunk => {
            newParagraphBlocks.push(paragraph(chunk))
        })

        blocks.splice(blockIndex, 1, ...newParagraphBlocks)

    }

})

@nprime496
Copy link

I tried your code with no success.

Did they update the requirements ? https://developers.notion.com/reference/request-limits

It looks like any array of more than 100 blocks is not allowed now.

@Wheest
Copy link

Wheest commented Aug 16, 2024

Also having this issue.

Tried to upload something and got the error Error adding block: 400 - {"object":"error","status":400,"code":"validation_error","message":"body failed validation: body.children.length should be ≤ 100, instead was 139.","request_id":""}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants