DEV Community

Željko Šević
Željko Šević

Posted on • Originally published at sevic.dev on

Integration with Notion API

Notion is a versatile workspace tool combining note-taking, task management, databases, and collaboration features into a single platform.

It also supports integration with Notion content, facilitating tasks such as creating pages, retrieving a block, and filtering database entries via API.

Prerequisites

  • Notion account
  • Generated Integration token (Settings & Members → Connections → Develop or manage integrations → New integration)
  • Notion database ID (open database as full page, extract database ID from the URL (https://notion.so/<USERNAME>/<DATABASE_ID>?v=v))
  • Added Notion connection (three dots (...) menu → Add Connections → choose created integration)
  • @notionhq/client package installed

Integration

Below is an example of interacting with Notion API to create the page (within the chosen database) with icon, cover, properties, and child blocks.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_INTEGRATION_TOKEN });

const response = await notion.pages.create({
  parent: {
    type: 'database_id',
    database_id: process.env.NOTION_DATABASE_ID,
  },
  icon: {
    type: 'emoji',
    emoji: '🆗',
  },
  cover: {
    type: 'external',
    external: {
      url: 'https://cover.com',
    },
  },
  properties: {
    Name: {
      title: [{
        type: 'text',
        text: {
          content: 'Some name',
        },
      }],
    },
    Score: {
      number: 42,
    },
    Tags: {
      multi_select: [{
        name: 'A',
      }, {
        name: 'B',
      }],
    },
    Generation: {
      select: {
        name: 'I',
      },
    },
    // other properties
  },
  children: [{
    object: 'block',
    type: 'bookmark',
    bookmark: {
      url: 'https://bookmark.com',
    },
  }],
});
Enter fullscreen mode Exit fullscreen mode

Course

Build your SaaS in 2 weeks - Start Now

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more