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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay