Handle all databases operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$databases
. Not to be instantiated directly.
Methods
Method new()
Initialise databases endpoint.
Not to be called directly, e.g., use notion$databases
instead.
Usage
DatabasesEndpoint$new(client)
Method create()
Create a database
Arguments
parent
Named list (JSON object) (required). The parent page where the database will be created.
title
List of lists (JSON array). Database title as an array of rich text objects.
properties
Named list (JSON object) (required). The properties of the database as key-value pairs.
...
<
dynamic-dots
> Additional body parameters to include in the request body.
Method query()
Query a database
Usage
DatabasesEndpoint$query(
database_id,
filter_properties = NULL,
filter = NULL,
sorts = NULL,
start_cursor = NULL,
page_size = 100,
...
)
Arguments
database_id
String (required). The ID of a Notion database.
filter_properties
Character vector. Property value IDs to include in the response schema.
filter
Named list (JSON object). Filter conditions to apply to the query.
sorts
List of lists (JSON array). Sort conditions to apply to the query.
start_cursor
Character. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_size
Integer. Number of items to return per page (1-100). Defaults to 100.
...
Reserved for future use.
Method update()
Update a database
Arguments
database_id
String (required). The ID of a Notion database.
title
List of lists (JSON array). Database title as an array of rich text objects.
description
List of lists (JSON array). Database description as an array of rich text objects.
properties
Named list (JSON object). Database properties to update as key-value pairs.
Examples
notion <- notion_client()
# ----- create a database
notion$databases$create(
parent = list(page_id = "23933ea0-c1e4-81d6-a6f6-dd5b57ad4aba"),
title = list(
list(
type = "text",
text = list(
content = "Grocery list"
)
)
),
properties = list(
Name = list(
title = no_config()
),
`In stock` = list(
checkbox = no_config()
)
)
)
#> {
#> "object": "database",
#> "id": "23933ea0-c1e4-8136-b37b-fa235c6f2a71",
#> "cover": {},
#> "icon": {},
#> "created_time": "2025-07-23T05:01:00.000Z",
#> "created_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_time": "2025-07-23T05:01:00.000Z",
#> "title": [
#> {
#> "type": "text",
#> "text": {
#> "content": "Grocery list",
#> "link": {}
#> },
#> "annotations": {
#> "bold": false,
#> "italic": false,
#> "strikethrough": false,
#> "underline": false,
#> "code": false,
#> "color": "default"
#> },
#> "plain_text": "Grocery list",
#> "href": {}
#> }
#> ],
#> "description": [],
#> "is_inline": false,
#> "properties": {
#> "In stock": {
#> "id": "q%3BL%5E",
#> "name": "In stock",
#> "type": "checkbox",
#> "checkbox": {}
#> },
#> "Name": {
#> "id": "title",
#> "name": "Name",
#> "type": "title",
#> "title": {}
#> }
#> },
#> "parent": {
#> "type": "page_id",
#> "page_id": "23933ea0-c1e4-81d6-a6f6-dd5b57ad4aba"
#> },
#> "url": "https://www.notion.so/23933ea0c1e48136b37bfa235c6f2a71",
#> "public_url": {},
#> "archived": false,
#> "in_trash": false,
#> "request_id": "c3a4224b-5923-46c2-9497-c5527eb10b92"
#> }
# ----- retrieve a database
notion$databases$retrieve(
"23933ea0-c1e4-8136-b37b-fa235c6f2a71"
)
#> {
#> "object": "database",
#> "id": "23933ea0-c1e4-8136-b37b-fa235c6f2a71",
#> "cover": {},
#> "icon": {},
#> "created_time": "2025-07-23T05:01:00.000Z",
#> "created_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_time": "2025-07-23T05:01:00.000Z",
#> "title": [
#> {
#> "type": "text",
#> "text": {
#> "content": "Grocery list",
#> "link": {}
#> },
#> "annotations": {
#> "bold": false,
#> "italic": false,
#> "strikethrough": false,
#> "underline": false,
#> "code": false,
#> "color": "default"
#> },
#> "plain_text": "Grocery list",
#> "href": {}
#> }
#> ],
#> "description": [],
#> "is_inline": false,
#> "properties": {
#> "In stock": {
#> "id": "q%3BL%5E",
#> "name": "In stock",
#> "type": "checkbox",
#> "checkbox": {}
#> },
#> "Name": {
#> "id": "title",
#> "name": "Name",
#> "type": "title",
#> "title": {}
#> }
#> },
#> "parent": {
#> "type": "page_id",
#> "page_id": "23933ea0-c1e4-81d6-a6f6-dd5b57ad4aba"
#> },
#> "url": "https://www.notion.so/23933ea0c1e48136b37bfa235c6f2a71",
#> "public_url": {},
#> "archived": false,
#> "in_trash": false,
#> "request_id": "f585fdc8-9acd-4ac1-a99f-26a882aea654"
#> }
# ----- update a database
notion$databases$update(
"23933ea0-c1e4-8136-b37b-fa235c6f2a71",
list(list(
text = list(
content = "Today's grocery list"
)
))
)
#> {
#> "object": "database",
#> "id": "23933ea0-c1e4-8136-b37b-fa235c6f2a71",
#> "cover": {},
#> "icon": {},
#> "created_time": "2025-07-23T05:01:00.000Z",
#> "created_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_time": "2025-07-23T05:01:00.000Z",
#> "title": [
#> {
#> "type": "text",
#> "text": {
#> "content": "Today's grocery list",
#> "link": {}
#> },
#> "annotations": {
#> "bold": false,
#> "italic": false,
#> "strikethrough": false,
#> "underline": false,
#> "code": false,
#> "color": "default"
#> },
#> "plain_text": "Today's grocery list",
#> "href": {}
#> }
#> ],
#> "description": [],
#> "is_inline": false,
#> "properties": {
#> "In stock": {
#> "id": "q%3BL%5E",
#> "name": "In stock",
#> "type": "checkbox",
#> "checkbox": {}
#> },
#> "Name": {
#> "id": "title",
#> "name": "Name",
#> "type": "title",
#> "title": {}
#> }
#> },
#> "parent": {
#> "type": "page_id",
#> "page_id": "23933ea0-c1e4-81d6-a6f6-dd5b57ad4aba"
#> },
#> "url": "https://www.notion.so/23933ea0c1e48136b37bfa235c6f2a71",
#> "public_url": {},
#> "archived": false,
#> "in_trash": false,
#> "request_id": "68c8b897-f3c1-4cde-a9f3-db92c20ebbb8"
#> }
# ----- query a database
notion$databases$query(
database_id = "23933ea0-c1e4-8136-b37b-fa235c6f2a71",
filter = list(
or = list(
list(
property = "In stock",
checkbox = list(equals = TRUE)
),
list(
property = "Name",
title = list(contains = "kale")
)
)
),
sorts = list(list(
property = "Name",
direction = "ascending"
))
)
#> {
#> "object": "list",
#> "results": [
#> {
#> "object": "page",
#> "id": "23933ea0-c1e4-8104-897b-f5a09269e561",
#> "created_time": "2025-07-23T05:01:00.000Z",
#> "last_edited_time": "2025-07-23T05:01:00.000Z",
#> "created_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "last_edited_by": {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081"
#> },
#> "cover": {},
#> "icon": {},
#> "parent": {
#> "type": "database_id",
#> "database_id": "23933ea0-c1e4-8136-b37b-fa235c6f2a71"
#> },
#> "archived": false,
#> "in_trash": false,
#> "properties": {
#> "In stock": {
#> "id": "q%3BL%5E",
#> "type": "checkbox",
#> "checkbox": true
#> },
#> "Name": {
#> "id": "title",
#> "type": "title",
#> "title": [
#> {
#> "type": "text",
#> "text": {
#> "content": "Tuscan Kale",
#> "link": {}
#> },
#> "annotations": {
#> "bold": false,
#> "italic": false,
#> "strikethrough": false,
#> "underline": false,
#> "code": false,
#> "color": "default"
#> },
#> "plain_text": "Tuscan Kale",
#> "href": {}
#> }
#> ]
#> }
#> },
#> "url": "https://www.notion.so/Tuscan-Kale-23933ea0c1e48104897bf5a09269e561",
#> "public_url": {}
#> }
#> ],
#> "next_cursor": {},
#> "has_more": false,
#> "type": "page_or_database",
#> "page_or_database": {},
#> "request_id": "7dde87ad-4cbf-4189-8b05-795e9609cc99"
#> }
# ----- iterate through paginated results
if (FALSE) { # \dontrun{
i <- 1
resps <- list()
has_more <- FALSE
start_cursor <- NULL
while (has_more) {
resps[[i]] <- notion$databases$query(
"22833ea0c1e481178e9cf1dcba79dbca",
start_cursor = start_cursor
)
has_more <- resps[[i]][["has_more"]]
start_cursor <- resps[[i]][["next_cursor"]]
i <- i + 1
}
} # }