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
nullif 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 aroundextractNotionId.
Signature
Example
extractDatabaseId
Extracts a database ID from a Notion database URL. This is a convenience wrapper aroundextractNotionId.
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 nullif the input is invalid or doesn’t contain a valid Notion ID
null before using the extracted ID.