0

Get Page as Markdown

by
Published May 6, 2025

Get a page's content as Notion-flavored Markdown.

Script notion Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 hours ago
1
//native
2

3
/**
4
 * Get Page as Markdown
5
 * Get a page's content as Notion-flavored Markdown. If `truncated` is true, fetch each ID in `unknown_block_ids` the same way to get the missing subtrees.
6
 */
7
export async function main(
8
  auth: RT.Notion,
9
  page_id: string,
10
  include_transcript: boolean = false
11
) {
12
  const url = new URL(`https://api.notion.com/v1/pages/${page_id}/markdown`)
13
  if (include_transcript) {
14
    url.searchParams.append("include_transcript", "true")
15
  }
16

17
  const response = await fetch(url, {
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      Accept: "application/json",
21
      "Notion-Version": "2026-03-11",
22
    },
23
  })
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  return await response.json()
30
}
31

Other submissions
  • Submitted by mryoga1995738 Bun
    Created 514 days ago
    1
    import { Client } from '@notionhq/client';
    2
    import { NotionToMarkdown } from 'notion-to-md';
    3
    
    
    4
    export async function main(appToken: string, pageId: string) {
    5
     return new Promise(async (resolve, reject) => {
    6
      let notion = new Client({
    7
        auth: appToken
    8
      });
    9
      const n2m = new NotionToMarkdown({ notionClient: notion });
    10
      const markdown = await n2m.pageToMarkdown(pageId)
    11
      .catch((err) => {
    12
        reject(err);
    13
        return 
    14
      });
    15
    
    
    16
      if (!markdown) {
    17
        reject("Failed to convert page to markdown");
    18
        return 
    19
      }
    20
      resolve(n2m.toMarkdownString(markdown))
    21
      return
    22
     })
    23
    }