Skip to content

Notion API, select all pages with a specific emoji

New Course Coming Soon:

Get Really Good at Git

Here’s something I used to select all subpages of a Notion page that used a specific emoji icon:

const notion = new Client({ auth: process.env.NOTION_API_KEY })
const pageId = process.env.NOTION_PAGE_ID

async function getAllSubpagesOfPage(page, notion) {
  const pages = []

  const blocks = await notion.blocks.children.list({
    block_id: page.id,
  })
  for (const block of blocks.results) {
    if (block.type === 'child_page') {
      //we need to add icons to the block because 
			//it's not provided by default
      const temp = await notion.pages.retrieve({ page_id: block.id })
      block.icon = temp.icon
      pages.push(block)
    }
  }

  return pages
}

const pages = await getAllSubpagesOfPage(page, notion)

pages.map(async (page) => {
  if (page.icon?.emoji === '✅') {
    //ok the page has that emoji
  }
})
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: