Skip to content

Get all pages title and url with Notion API

homepage-banner

To generate sitemap.xml for a Notion based website, you need list of all shared with integration pages and urls are needed.

Introduction

Notion is a popular productivity tool that allows organizations and individuals to create and organize notes, databases, and projects. With the Notion API, developers can build custom integrations to automate workflows, extract data, and interact with Notion programmatically. In this blog post, we will explore how to use the Notion API to get all the pages’ titles and URLs in a Notion database.

Getting Started

Before we dive into the code, you need to set up a few things:

  1. Create a Notion account and sign in.
  2. Create a database and add some pages to it.
  3. Enable the Notion API and get an integration token.

Get all pages title and url in Notion API

curl -s -X POST 'https://api.notion.com/v1/search' \
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
  -H 'Content-Type: application/json' \
  -H 'Notion-Version: 2022-06-28' \
  --data '{
    "filter": {
        "value": "page",
        "property": "object"
    },
    "sort":{
      "direction":"descending",
      "timestamp":"last_edited_time"
    }
  }'

Reference

  • https://developers.notion.com/reference/post-search
  • https://developers.notion.com/reference/post-database-query
  • https://github.com/tangly1024/NotionNext
Leave your message