No description
Find a file
Vojtěch Mareš 63da7f26d1
docs: add README.md with notes
Signed-off-by: Vojtěch Mareš <vojtech@mares.cz>
2025-05-07 23:50:04 +02:00
src feat: add database query filters and sorts 2025-05-07 17:58:33 +02:00
.env.example feat: initial commit 2025-05-07 17:13:17 +02:00
.gitignore feat: initial commit 2025-05-07 17:13:17 +02:00
package.json refactor: use typescript 2025-05-07 17:30:19 +02:00
pnpm-lock.yaml refactor: use typescript 2025-05-07 17:30:19 +02:00
README.md docs: add README.md with notes 2025-05-07 23:50:04 +02:00

notion-database

Fetch pages (entries) from database and map/transform the pages to a type.

Notion

Notion key

How to obtain new API key and connect it to database/page/etc.:

  1. Go to https://www.notion.so/profile/integrations
  2. Click 'New integration'
  3. Name the integration
  4. Select workspace and type
  5. Save new integration
  6. Continue to integration settings
  7. Copy the key and keep it safe!
  8. Modify capabilities as needed
  9. Go to your workspace to the page/database
  10. Click the three dots (top right corner) and select connections
  11. Add your new integration to grant access to the page/database to the integration

Database ID

Go to Notion GUI on web, to the database, copy the hash/ID.

Example:

The URL is https://www.notion.so/mareshq/1eb611d502b1807bbc5df523a3acc322?v=1eb611d502b180218d5b000c62cd80a8, the database ID is 1eb611d502b1807bbc5df523a3acc322 and its located in the path, the segment after /mareshq/<database-id>. Aka https://www.notion.so/<workspace-slug>/<database-id>.

Working with the Notion SDK (@notionhq/client)

The JavaScript SDK is only a simple wrapper on top of Notion's HTTP API, therefore only generic types are available and I find it tricky to work with types.

Instead of trying to figure out the types with the type definition, go to the API documentation (see Notion Developer portal)and work with the schema from there. It was much easier.

Also type casting response pages is tricky, just do mapping. But you will have to do a lot of null checks, without them you will pray that everything works. Until it breaks. This proof-of-concept does not check for null, but you should!