{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "notion-create-database-entry", "type": "registry:item", "description": "Create an entry in a Notion database", "dependencies": [], "files": [ { "path": "steps/notion-create-database-entry.ts", "content": "/**\n * Create an entry in a Notion database\n *\n * @param databaseId - The database ID\n * @param properties - Object containing property names and values\n * @returns The created database entry with ID\n *\n * @env NOTION_API_KEY - Notion integration token\n */\n\nimport { FatalError } from \"workflow\"\n\ninterface CreateDatabaseEntryOptions {\n databaseId: string\n properties: Record\n}\n\nexport async function notionCreateDatabaseEntry({ databaseId, properties }: CreateDatabaseEntryOptions) {\n \"use step\"\n\n const apiKey = process.env.NOTION_API_KEY\n if (!apiKey) {\n throw new FatalError(\"NOTION_API_KEY environment variable is required\")\n }\n\n if (!databaseId || !properties) {\n throw new FatalError(\"databaseId and properties are required\")\n }\n\n // Convert simple values to Notion property format\n const notionProperties: Record = {}\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === \"string\") {\n notionProperties[key] = {\n rich_text: [{ text: { content: value } }],\n }\n } else if (typeof value === \"number\") {\n notionProperties[key] = { number: value }\n } else if (typeof value === \"boolean\") {\n notionProperties[key] = { checkbox: value }\n } else {\n notionProperties[key] = value\n }\n }\n\n const response = await fetch(\"https://api.notion.com/v1/pages\", {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n \"Notion-Version\": \"2022-06-28\",\n },\n body: JSON.stringify({\n parent: { database_id: databaseId },\n properties: notionProperties,\n }),\n })\n\n if (!response.ok) {\n const error = await response.text()\n throw new Error(`Failed to create Notion database entry: ${error}`)\n }\n\n const data = await response.json()\n return {\n id: data.id,\n url: data.url,\n createdTime: data.created_time,\n }\n}\n", "type": "registry:file", "target": "steps/notion-create-database-entry.ts" } ] }