How to retrieve Notion page markdown using their API?

Hey everyone! I’m working on a cool project to create a blog using the Notion API. I’m trying to figure out how to fetch the markdown content from my Notion pages and display it on my blog. I’ve been digging through the API docs but can’t seem to find anything about getting the actual page content. Am I missing something obvious? Has anyone successfully pulled markdown from Notion pages using their API? Any tips or code snippets would be super helpful! I’m really excited about this project and would love to get it working. Thanks in advance for any advice!

I’ve worked with the Notion API recently and encountered a similar challenge. Unfortunately, there’s no direct way to fetch markdown content from Notion pages using their API. The API returns page content in a structured block format, not as markdown.

However, you can retrieve the page content as blocks and then convert those blocks to markdown. Here’s a high-level approach:

  1. Use the ‘retrieve block children’ endpoint to get the page content.
  2. Iterate through the returned blocks, parsing each type (paragraph, heading, list, etc.).
  3. Convert the parsed blocks into markdown format.

There are some open-source libraries that can help with this conversion process. You might want to check out ‘notion-to-md’ on npm if you’re using JavaScript. It simplifies the process of turning Notion blocks into markdown.

Hope this helps point you in the right direction!

I’ve been down this road before, and it can be a bit tricky. The Notion API doesn’t provide markdown directly, which is a pain. What I ended up doing was fetching the block content and then converting it myself. It’s not ideal, but it works.

One approach that saved me a ton of time was using a library called notionapi-md. It’s not perfect, but it handles most of the conversion heavy lifting. You’ll still need to do some tweaking, especially for more complex page layouts.

Word of caution though - keep an eye on your API rate limits. If you’re pulling content for a lot of pages, you might hit those limits pretty quick. I ended up implementing a caching system to avoid constantly hitting the API.

Stick with it - once you get it working, it’s pretty satisfying to see your Notion content flowing into your blog seamlessly!

hey swiftcoder42, I ran into this too! notion’s API doesn’t give markdown directly :frowning: but u can get the blocks and convert em. there’s a npm package called notion-to-md that does the heavy lifting. it’s pretty easy to use, just feed it the blocks and it spits out markdown. good luck with ur blog project!

The notion-to-md package works if you’re writing custom code, but for Latenode workflows it’s easier to use an API service that does the conversion.

Mark2Notion handles this - just pass your Notion token and page ID via HTTP request, get clean markdown back. Works well with Latenode’s HTTP node.

https://mark2notion.com Docs: Notion to Markdown - mark2notion API