Skip to main content

Method

client.dataSources.create(parameters: CreateDataSourceParameters): Promise<DataSourceObjectResponse | PartialDataSourceObjectResponse>
Creates a new data source within a parent database. Data sources are structured data containers that can be queried and managed independently.

Parameters

parent
object
required
The parent database where the data source will be created.
parent.type
string
default:"database_id"
Always database_id
parent.database_id
string
required
The ID of the parent database (with or without dashes)
properties
Record<string, PropertyConfiguration>
required
Property schema of the data source. Each key is a property name, and each value is a property configuration object.Supported property types:
  • title - Title property (required for data sources)
  • rich_text - Rich text content
  • number - Numeric values
  • select - Single select from options
  • multi_select - Multiple selections
  • date - Date or date range
  • people - User references
  • files - File attachments
  • checkbox - Boolean values
  • url - URL strings
  • email - Email addresses
  • phone_number - Phone numbers
  • formula - Calculated values
  • relation - Relations to other data sources
  • rollup - Aggregate values from relations
  • created_time - Automatic creation timestamp
  • created_by - Automatic creator reference
  • last_edited_time - Automatic edit timestamp
  • last_edited_by - Automatic editor reference
title
RichTextItemRequest[]
Title of the data source as it appears in Notion. Array of rich text objects.
icon
PageIconRequest | null
Icon for the data source. Can be an emoji, external URL, or file upload.
auth
string
Bearer token for authentication. Overrides the client-level auth if provided.

Response

Returns a DataSourceObjectResponse or PartialDataSourceObjectResponse.
object
string
Always "data_source"
id
string
The unique identifier of the data source
title
RichTextItemResponse[]
The title of the data source
description
RichTextItemResponse[]
The description of the data source
parent
object
The parent of the data source (database or another data source)
properties
Record<string, DatabasePropertyConfigResponse>
The property schema of the data source
created_time
string
ISO 8601 timestamp when the data source was created
last_edited_time
string
ISO 8601 timestamp when the data source was last edited
created_by
PartialUserObjectResponse
The user who created the data source
last_edited_by
PartialUserObjectResponse
The user who last edited the data source
icon
PageIconResponse | null
The icon of the data source
cover
PageCoverResponse | null
The cover image of the data source
url
string
The Notion URL of the data source
archived
boolean
Whether the data source is archived
in_trash
boolean
Whether the data source is in the trash

Example

import { Client } from "@notionhq/client"

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

const dataSource = await notion.dataSources.create({
  parent: {
    database_id: "195de9221179449fab8075a27c979105"
  },
  properties: {
    Name: {
      title: {}
    },
    Description: {
      rich_text: {}
    },
    Status: {
      select: {
        options: [
          { name: "Active", color: "green" },
          { name: "Inactive", color: "gray" }
        ]
      }
    },
    Count: {
      number: {
        format: "number"
      }
    }
  },
  title: [
    {
      type: "text",
      text: { content: "My Data Source" }
    }
  ],
  icon: {
    type: "emoji",
    emoji: "📊"
  }
})

console.log(`Created data source: ${dataSource.id}`)

Build docs developers (and LLMs) love