souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 90 forks source link

"Could not find block" error #59

Closed t3db0t closed 1 year ago

t3db0t commented 1 year ago

I'm using the first example from the readme to get the markdown from a page. I have added the integration to the relevant page and copied the page ID (correctly) from the page. However, when I run the script, I get a 404 "Could not find block" error for a different page ID. I have no idea why this is happening. Am I missing something? What can I do to debug this?

Code:

const { Client } = require("@notionhq/client");
const { NotionToMarkdown } = require("notion-to-md");
const fs = require('node:fs/promises');

const TOKEN = process.env.TOKEN;

const notion = new Client({
  auth: TOKEN,
});

// passing notion client to the option
const n2m = new NotionToMarkdown({ notionClient: notion });

(async () => {
  const mdblocks = await n2m.pageToMarkdown("d82b628c-e95a-4723-82fc-67aaec962db9");
  const mdString = n2m.toMarkdownString(mdblocks);

  //writing to file
  fs.writeFile("test.md", mdString, (err) => {
    console.log(err);
  });
})();

Error:

@notionhq/client warn: request fail {
  code: 'object_not_found',
  message: 'Could not find block with ID: dfc6d411-0a31-45d6-ba51-be5ea4be0cf5. Make sure the relevant pages and databases are shared with your integration.'
}

Note that the block ID in the error is different than what I am supplying in my script.

souvikinator commented 1 year ago

Can you share what your notion page looks like? Screen shot?

t3db0t commented 1 year ago

This is the page I'm trying to render to markdown: https://t3db0t.notion.site/Sentients-Core-Rulebook-d82b628ce95a472382fc67aaec962db9

It contains a lot of nested Pages and links, not sure if that's the problem?

t3db0t commented 1 year ago

After a bunch of debugging, it appears that the parent of the block that's giving the 404 is a synced_block so maybe the child or parent doesn't have the right permissions.

souvikinator commented 1 year ago

So I tried to use it with normal nested pages and it works fine.

I tried using synced block as well and it works fine. With synced block I used the one that doesn't have permission to access and it skipped the synced page. Not sure what is the issue you are facing.

If you can provide some steps to reproduce. I tried duplicating your page to try it on but I believe duplicating is not enabled

t3db0t commented 1 year ago

I removed the synced page and I'm not getting the error anymore so I'll go ahead and close this