Reputation: 319
I'm planning to make some blog using notion api.
I would like to use the notion api to bring the notion page markdown and show on my blog.
But, I can't find to get page content..
Is there a way to import page markdown content using api?
Upvotes: 7
Views: 10597
Reputation: 968
You need to use Notion's Blocks API. Treat a page as a block, and get its children:
curl 'https://api.notion.com/v1/blocks/<your-page-id>/children?page_size=100' \
-H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
-H "Notion-Version: 2022-02-22"
Please remember that the content will come up as an array of text pieces that you will need to stitch together.
Upvotes: 8
Reputation: 11
You can use notion-to-md.
Here's an example of an action in Nest. In this case authorization header is Internal Integration Token
from Notion (you can get it here, just create an internal integration) and pageId from body params is just ID of Notion page.
Please note a page you want to get content from, needs to be connected with this integration (see this Screenshot).
@Post('/markdown')
async convertBlocksToMarkdown(
@Req() request,
@Body() body,
): Promise<{ markdown: string }> {
const auth = request.headers.authorization;
const notionClient = new Client({ auth });
const n2m = new NotionToMarkdown({ notionClient });
const mdblocks = await n2m.pageToMarkdown(body.pageId);
const markdown = n2m.toMarkdownString(mdblocks);
return {
markdown
};
}
Upvotes: 1
Reputation: 2479
You cannot get the page as markdown via the API as of the current version, 2022-06-28
. There is an export option in the UI but this is not accessible via the API.
You can get the page content using the blocks endpoint which will return a JSON format of blocks and may require multiple requests to get everything, and the formatting of the text blocks uses a JSON representation for markup as well.
Upvotes: 2