A comprehensive API for enhancing Notion pages with web content utilities. This API provides several endpoints to extract and update information from web pages to Notion, including favicons, page titles, domain information, and embeds.
This API serves as a bridge between web content and Notion pages, allowing you to:
- Extract favicons from websites and set them as Notion page icons
- Extract page titles from websites and update Notion page titles
- Extract domain information from URLs in Notion pages
- Add URL embeds to Notion pages
- Generate showcases of web content
- Store Notion database information in blob storage
- Create cron jobs for specific Notion databases
The API is built using Hono, a lightweight web framework, with modular routes for better organization and maintainability.
/
├── index.tsx # Main entry point for the API
├── process-notion-dbs.ts # Cron job to process Notion database blobs
├── create-db-crons.ts # Cron job to create database-specific cron files
├── routes/ # Directory for API route modules
│ ├── blob.tsx # Blob storage for Notion databases
│ ├── create-cron.tsx # Endpoint to create cron files for blobs
│ ├── domain.tsx # Domain extraction endpoint
│ ├── embed.tsx # URL embed endpoint
│ ├── favicon.tsx # Favicon extraction endpoint
│ ├── showcase.tsx # Content showcase endpoint
│ ├── showcaseHTML.tsx # HTML showcase endpoint
│ ├── test-domain.tsx # Domain testing endpoint
│ └── title.tsx # Title extraction endpoint
├── utils/ # Utility functions
│ ├── getDomain.tsx # Function to extract domain from URL
│ └── getTitle.tsx # Function to extract title from URL
└── README.md # This documentation file
Returns a list of available endpoints.
Example Response:
API Gateway - Available endpoints: /domain, /title, /favicon, /test-domain, /embed, /showcase, /showcase-html, /blob, /create-cron
Extracts a favicon from a URL in a Notion page and updates the page icon.
Request Body:
{ "data": { "id": "notion-page-id" } }
Success Response:
{ "success": true, "message": "Favicon found and Notion page updated", "pageId": "notion-page-id", "url": "https://example.com", "faviconUrl": "https://example.com/favicon.ico" }
Error Response:
{ "success": false, "error": "Failed to retrieve Notion page", "message": "Error details", "pageId": "notion-page-id" }
Handles Notion webhooks to extract a favicon from a URL and update the corresponding Notion page with the favicon.
Request Body:
{ "pageId": "notion-page-id" }
Success Response:
{ "success": true, "message": "Favicon found and Notion page updated", "pageId": "notion-page-id", "url": "https://example.com", "faviconUrl": "https://example.com/favicon.ico" }
Extracts the domain from a URL property in a Notion page and updates the Domain property.
Request Body:
{ "data": { "id": "notion-page-id" } }
Success Response: Returns the updated Notion page object.
Test endpoint to verify the domain extraction API is working.
Response:
Hello World!
Extracts the title from a URL in a Notion page and updates the page title.
Request Body:
{ "data": { "id": "notion-page-id" } }
Success Response: Returns the updated Notion page object.
Error Response:
{ "error": "Error message", "stack": "Error stack trace" }
Test endpoint to verify the title extraction API is working.
Response:
Title Extractor API is running!
Test endpoint for the getTitle function.
Query Parameters:
url
: The URL to extract the title from
Success Response:
{ "url": "https://example.com", "title": "Example Domain" }
Adds an embed block with the provided URL to a Notion page.
Request Body:
{ "pageId": "notion-page-id", "url": "https://example.com" }
Retrieves information about a Notion database and stores it in blob storage.
Path Parameters:
id
: The Notion database ID
Success Response:
{ "id": "database-id" }
Creates a cron file template for a specific blob key and sends instructions via email.
Path Parameters:
blobKey
: The blob key to create a cron file for (format: dbTitle--dbId)
Success Response:
{ "success": true, "message": "Cron file creation instructions sent via email", "blobKey": "dbTitle--dbId", "cronFileName": "/dbTitle--dbId.ts", "dbTitle": "Database Title", "dbId": "database-id" }
Endpoints for showcasing content, likely for preview purposes.
The project includes several cron jobs for processing Notion database information:
A cron job that processes all Notion database blobs stored in the system. It:
- Retrieves all blobs with keys that match the pattern
dbTitle--dbId
- For each blob, fetches the latest data from the Notion database
- Updates the blob with the latest information
A cron job that creates individual cron files for each Notion database blob:
- Scans for all blobs with keys that match the pattern
dbTitle--dbId
- For each blob, generates a cron file template with the same name as the blob key
- Stores the cron file template in a blob for reference
When you access a Notion database through the /blob/:id
endpoint, it creates a blob with a key in the format dbTitle--dbId
. You can then use the /create-cron/:blobKey
endpoint to generate a cron file with the same name as the blob key.
These database-specific cron files will:
- Run on a schedule (configurable in the Val Town UI)
- Fetch the latest data from the specific Notion database
- Update the corresponding blob with the latest information
The favicon endpoint uses multiple strategies to extract a favicon:
- First tries Google's Favicon API for reliable results
- If that fails, tries the standard
/favicon.ico
path - If that fails, it parses the HTML to find favicon link tags
- Returns the favicon URL and updates the Notion page icon
- Falls back to a globe emoji (🌐) if no favicon can be found
The title extraction is sophisticated and handles various edge cases:
- Special handling for YouTube URLs using their oEmbed API
- Special handling for news sites with anti-scraping measures
- Multiple fallback strategies including:
- OpenGraph meta tags
- Twitter card meta tags
- Standard title tags
- Google search results
- URL slug parsing
Extracts the domain (including protocol) from a URL:
- Handles URLs without protocol by adding https:// as default
- Parses the URL to extract the origin (protocol + hostname)
- Updates the Domain property in the Notion page
This API requires the following environment variable:
NOTION_API_KEY
: Your Notion API integration token
You'll need to create an integration in the Notion workspace and grant it access to the relevant pages or databases.
curl -X POST https://your-api-url/favicon \ -H "Content-Type: application/json" \ -d '{"data":{"id":"your-notion-page-id"}}'
curl -X GET "https://your-api-url/title/test?url=https://example.com"
curl -X POST https://your-api-url/title \ -H "Content-Type: application/json" \ -d '{"data":{"id":"your-notion-page-id"}}'
To add a new route:
- Create a new file in the
/routes
directory - Export a Hono router with your endpoint handlers
- Import and mount the router in
index.tsx
Example:
// In /routes/newEndpoint.ts
import { Hono } from "npm:hono@3";
const router = new Hono();
router.get("/", (c) => {
return c.json({ message: "New endpoint" });
});
export default router;
// In index.tsx
import newEndpoint from "./routes/newEndpoint.tsx";
// Mount the new router
app.route("/new-endpoint", newEndpoint);
The API includes comprehensive error handling:
- Detailed error messages for debugging
- Fallback strategies for common failure scenarios
- Error unwrapping to see original error details
This API integrates with the Notion API to:
- Retrieve page data including properties like URL and Domain
- Update page properties with extracted information
- Set page icons using extracted favicons
- Add embed blocks to pages
The integration requires a Notion API key and appropriate permissions to access and modify the pages.