Skip to main content

Overview

Creates a new database as a child of an existing page or in the workspace. Databases are containers that can hold one or more data sources.
const database = await notion.databases.create({
  parent: {
    type: 'page_id',
    page_id: 'parent-page-id'
  },
  title: [
    {
      type: 'text',
      text: { content: 'Project Database' }
    }
  ],
  initial_data_source: {
    properties: {
      Name: {
        title: {}
      },
      Status: {
        select: {
          options: [
            { name: 'Not started', color: 'gray' },
            { name: 'In progress', color: 'blue' },
            { name: 'Complete', color: 'green' }
          ]
        }
      }
    }
  }
})

Parameters

parent
object
required
The parent page or workspace where the database will be created.
title
array
The title of the database as an array of rich text objects.
description
array
The description of the database as an array of rich text objects.
is_inline
boolean
default:"false"
Whether the database should be displayed inline in the parent page.
initial_data_source
object
Initial data source configuration for the database.
icon
object
The icon for the database. Can be an emoji, external URL, or file upload.
cover
object
The cover image for the database. Can be an external URL or file upload.
auth
string
Optional authentication token to override the client’s default token for this request.

Response

Returns a DatabaseObjectResponse or PartialDatabaseObjectResponse.
object
string
Always database.
id
string
The ID of the database.
title
array
The title of the database as an array of rich text objects.
description
array
The description of the database as an array of rich text objects.
parent
object
The parent page or workspace of the database.
is_inline
boolean
Whether the database is displayed inline in the parent page.
is_locked
boolean
Whether the database is locked from editing in the Notion app UI.
in_trash
boolean
Whether the database is in the trash.
created_time
string
ISO 8601 timestamp when the database was created.
last_edited_time
string
ISO 8601 timestamp when the database was last edited.
data_sources
array
Array of data source references contained in this database.
icon
object
The icon of the database.
cover
object
The cover image of the database.
url
string
The URL of the database in Notion.
public_url
string
The public URL of the database if it is publicly accessible, otherwise null.

Examples

Create a database in a page

const database = await notion.databases.create({
  parent: {
    type: 'page_id',
    page_id: '897e5a76-ae52-4b48-a6d4-0b46543ebcda'
  },
  title: [
    {
      type: 'text',
      text: { content: 'Tasks' }
    }
  ],
  initial_data_source: {
    properties: {
      Name: {
        title: {}
      },
      Status: {
        select: {
          options: [
            { name: 'To Do', color: 'red' },
            { name: 'In Progress', color: 'yellow' },
            { name: 'Done', color: 'green' }
          ]
        }
      },
      Priority: {
        select: {
          options: [
            { name: 'High', color: 'red' },
            { name: 'Medium', color: 'yellow' },
            { name: 'Low', color: 'gray' }
          ]
        }
      },
      'Due Date': {
        date: {}
      }
    }
  }
})

console.log(database.id)

Create a database in workspace

const database = await notion.databases.create({
  parent: {
    type: 'workspace',
    workspace: true
  },
  title: [
    {
      type: 'text',
      text: { content: 'Company Directory' }
    }
  ],
  description: [
    {
      type: 'text',
      text: { content: 'Employee contact information' }
    }
  ],
  icon: {
    type: 'emoji',
    emoji: '👥'
  },
  initial_data_source: {
    properties: {
      Name: {
        title: {}
      },
      Email: {
        email: {}
      },
      Department: {
        select: {
          options: [
            { name: 'Engineering', color: 'blue' },
            { name: 'Product', color: 'purple' },
            { name: 'Sales', color: 'green' }
          ]
        }
      }
    }
  }
})

Create an inline database

const database = await notion.databases.create({
  parent: {
    type: 'page_id',
    page_id: 'parent-page-id'
  },
  title: [
    {
      type: 'text',
      text: { content: 'Quick Notes' }
    }
  ],
  is_inline: true,
  initial_data_source: {
    properties: {
      Title: {
        title: {}
      },
      Tags: {
        multi_select: {
          options: [
            { name: 'Important', color: 'red' },
            { name: 'Personal', color: 'blue' },
            { name: 'Work', color: 'green' }
          ]
        }
      }
    }
  }
})
After creating a database, you can query its data sources using notion.dataSources.query().

Build docs developers (and LLMs) love