Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix(notion): migrate unofficial API to app.notion.com

Marc Seitz6916c16b25a6
diff --git a/components/documents/notion-accessibility-indicator.tsx b/components/documents/notion-accessibility-indicator.tsx
index 32086d7a..24e1bff8 100644
--- a/components/documents/notion-accessibility-indicator.tsx
+++ b/components/documents/notion-accessibility-indicator.tsx
@@ -271,7 +271,7 @@ export default function NotionAccessibilityIndicator({
id="notion-url"
value={newUrl}
onChange={(e) => setNewUrl(e.target.value)}
- placeholder="https://www.notion.so/your-page-url"
+ placeholder="https://www.notion.com/your-page-url"
className="w-full"
/>
</div>
diff --git a/lib/notion/index.ts b/lib/notion/index.ts
index b207bae3..2bad1f27 100644
--- a/lib/notion/index.ts
+++ b/lib/notion/index.ts
@@ -1,9 +1,11 @@
import { NotionAPI } from "notion-client";
-// Cloudflare 403s requests to www.notion.so that carry no User-Agent, and
-// neither undici nor notion-client sets one. It has to look like a browser.
+// Notion is decommissioning www.notion.so for the unofficial API in favor of
+// app.notion.com. notion-client 7.10.0 still defaults to notion.so.
+// Keep a User-Agent as well — Cloudflare has 403'd UA-less Node fetches.
// https://github.com/NotionX/react-notion-x/issues/710
const notion = new NotionAPI({
+ apiBaseUrl: "https://app.notion.com/api/v3",
ofetchOptions: {
headers: {
"User-Agent":
diff --git a/lib/notion/utils.ts b/lib/notion/utils.ts
index 237eab63..b30a88dc 100644
--- a/lib/notion/utils.ts
+++ b/lib/notion/utils.ts
@@ -306,6 +306,23 @@ export const addSignedUrls: NotionAPI["addSignedUrls"] = async ({
}
};
+const NOTION_APP_HOSTNAMES = new Set([
+ "www.notion.so",
+ "notion.so",
+ "www.notion.com",
+ "notion.com",
+ "app.notion.com",
+]);
+
+// Matches getNotionPageIdFromSlug: only single-label *.notion.site hosts.
+const NOTION_SITE_HOSTNAME_RE = /^[^.]+\.notion\.site$/;
+
+export function isStandardNotionHostname(hostname: string): boolean {
+ return (
+ NOTION_APP_HOSTNAMES.has(hostname) || NOTION_SITE_HOSTNAME_RE.test(hostname)
+ );
+}
+
/**
* Extracts page ID from custom Notion domain URLs
* For custom domains, the page ID is typically embedded in the URL slug
@@ -357,17 +374,17 @@ export async function getNotionPageIdFromSlug(
const urlObj = new URL(url);
const hostname = urlObj.hostname;
- const isNotionSo = hostname === "www.notion.so" || hostname === "notion.so";
- const isNotionSite = hostname.endsWith(".notion.site");
+ const isNotionApp = NOTION_APP_HOSTNAMES.has(hostname);
+ const isNotionSite = NOTION_SITE_HOSTNAME_RE.test(hostname);
- // notion.so: extract ID from path directly
- if (isNotionSo) {
+ // notion.so / notion.com / app.notion.com: extract ID from path directly
+ if (isNotionApp) {
const pageId = parsePageId(url) ?? parsePageId(urlObj.pathname);
if (pageId) return pageId;
throw new Error(`Unable to extract page ID from Notion URL: ${url}`);
}
- // Custom domains (non notion.site, non notion.so)
+ // Custom domains (anything outside NOTION_APP_HOSTNAMES and *.notion.site)
if (!isNotionSite) {
const pageId = extractPageIdFromCustomNotionUrl(url);
if (pageId) {
diff --git a/lib/zod/url-validation.ts b/lib/zod/url-validation.ts
index c7a53688..6fa16318 100644
--- a/lib/zod/url-validation.ts
+++ b/lib/zod/url-validation.ts
@@ -8,6 +8,7 @@ import {
import {
getNotionPageIdFromSlug,
isCustomNotionDomain,
+ isStandardNotionHostname,
} from "@/lib/notion/utils";
import { isPublicHostnameLiteral } from "@/lib/utils/ssrf-protection";
import { getSupportedContentType } from "@/lib/utils/get-content-type";
@@ -77,12 +78,7 @@ const createFilePathValidator = () => {
const urlObj = new URL(path);
const hostname = urlObj.hostname;
- // Valid notion domains
- const validNotionDomains = ["www.notion.so", "notion.so"];
-
- // Check for notion.site subdomains (e.g., example-something.notion.site)
- const isNotionSite = hostname.endsWith(".notion.site");
- const isValidNotionDomain = validNotionDomains.includes(hostname);
+ const isValidNotionDomain = isStandardNotionHostname(hostname);
// Check for vercel blob storage
let isVercelBlob = false;
@@ -91,7 +87,7 @@ const createFilePathValidator = () => {
}
// If it's not a standard Notion domain or Vercel blob, check if it's a custom Notion domain
- if (!isNotionSite && !isValidNotionDomain && !isVercelBlob) {
+ if (!isValidNotionDomain && !isVercelBlob) {
try {
let pageId = parsePageId(path);
if (!pageId) {
@@ -106,7 +102,7 @@ const createFilePathValidator = () => {
}
}
- return isNotionSite || isValidNotionDomain || isVercelBlob;
+ return isValidNotionDomain || isVercelBlob;
} catch {
return false;
}
@@ -149,13 +145,10 @@ export const notionUrlUpdateSchema = z
const urlObj = new URL(url);
const hostname = urlObj.hostname;
- // Valid notion domains
- const validNotionDomains = ["www.notion.so", "notion.so"];
- const isNotionSite = hostname.endsWith(".notion.site");
- const isValidNotionDomain = validNotionDomains.includes(hostname);
+ const isValidNotionDomain = isStandardNotionHostname(hostname);
// If it's a standard Notion domain, try to extract page ID
- if (isNotionSite || isValidNotionDomain) {
+ if (isValidNotionDomain) {
let pageId = parsePageId(url);
if (!pageId) {
try {
@@ -185,7 +178,7 @@ export const notionUrlUpdateSchema = z
},
{
message:
- "Must be a valid Notion URL (supports notion.so, notion.site, and custom domains)",
+ "Must be a valid Notion URL (supports app.notion.com, notion.com, notion.so, notion.site, and custom domains)",
},
)
.refine(
@@ -309,12 +302,7 @@ export const documentUploadSchema = z
try {
const urlObj = new URL(data.url);
const hostname = urlObj.hostname;
- const isStandardNotion =
- hostname === "www.notion.so" ||
- hostname === "notion.so" ||
- hostname.endsWith(".notion.site");
-
- if (isStandardNotion) {
+ if (isStandardNotionHostname(hostname)) {
return true;
}
@@ -343,12 +331,8 @@ export const documentUploadSchema = z
try {
const urlObj = new URL(data.url);
const hostname = urlObj.hostname;
- const isStandardNotion =
- hostname === "www.notion.so" ||
- hostname === "notion.so" ||
- hostname.endsWith(".notion.site");
- if (isStandardNotion) {
+ if (isStandardNotionHostname(hostname)) {
return true;
}