Get all pages title and url in Notion API
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:
- Create a Notion account and sign in.
- Create a database and add some pages to it.
- 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 a message
Disclaimer
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- Made with Material for MkDocs and improve writing by generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @