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
The parent page or workspace where the database will be created.
The type of parent. Either page_id or workspace.
The ID of the parent page. Required when type is page_id.
Must be true when type is workspace.
The title of the database as an array of rich text objects.
The description of the database as an array of rich text objects.
Whether the database should be displayed inline in the parent page.
Initial data source configuration for the database.
Property schema for the initial data source. A record where keys are property names and values are property configuration objects.
The icon for the database. Can be an emoji, external URL, or file upload.
The cover image for the database. Can be an external URL or file upload.
Optional authentication token to override the client’s default token for this request.
Response
Returns a DatabaseObjectResponse or PartialDatabaseObjectResponse.
The title of the database as an array of rich text objects.
The description of the database as an array of rich text objects.
The parent page or workspace of the database.
Whether the database is displayed inline in the parent page.
Whether the database is locked from editing in the Notion app UI.
Whether the database is in the trash.
ISO 8601 timestamp when the database was created.
ISO 8601 timestamp when the database was last edited.
Array of data source references contained in this database.
The icon of the database.
The cover image of the database.
The URL of the database in Notion.
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().