Skip to main content
The Notion SDK provides utilities to extract properly formatted UUIDs from Notion URLs or raw ID strings.

extractNotionId

Extracts a Notion ID from a Notion URL or returns the input if it’s already a valid ID. This is the primary function that all other extraction helpers use internally.

Signature

Parameters

  • urlOrId - A Notion URL or ID string

Returns

  • The extracted UUID in standard format (with hyphens) or null if invalid

Features

  • Accepts URLs, compact IDs (32 hex chars), or formatted UUIDs
  • Prioritizes path IDs over query parameters to avoid extracting view IDs instead of database IDs
  • Returns IDs in standard UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • Case-insensitive

Examples

extractPageId

Extracts a page ID from a Notion page URL. This is a convenience wrapper around extractNotionId.

Signature

Example

extractDatabaseId

Extracts a database ID from a Notion database URL. This is a convenience wrapper around extractNotionId.

Signature

Example

extractBlockId

Extracts a block ID from a Notion URL with a block fragment. Looks for #block-<id> or #<id> patterns.

Signature

Example

Common Use Cases

Converting User-Provided URLs

When users share Notion URLs, use these helpers to extract the ID:

Handling Database URLs with View Parameters

The extractors prioritize database IDs over view IDs:

Working with Multiple ID Formats

Return Value

All extraction functions return:
  • A string in standard UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) if successful
  • null if the input is invalid or doesn’t contain a valid Notion ID
Always check for null before using the extracted ID.