| Title: | Client for the 'Notion API' |
| Version: | 0.2.0 |
| Description: | Enable programmatic interaction with 'Notion' pages, databases, blocks, comments, and users through the 'Notion API' https://developers.notion.com/. Provides both synchronous and asynchronous client interfaces for building workflows and automations that integrate with 'Notion' workspaces. Supports all 'Notion API' endpoints including content creation, data retrieval, and workspace management. |
| License: | MIT + file LICENSE |
| URL: | https://brenwin1.github.io/notionapi/, https://github.com/brenwin1/notionapi |
| BugReports: | https://github.com/brenwin1/notionapi/issues |
| Imports: | cli, httr2, jsonlite, R6, rlang |
| Suggests: | curl, promises, testthat (≥ 3.0.0), vcr (≥ 2.0.0) |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-04-12 21:41:59 UTC; brenwin |
| Author: | Brenwin Ang [aut, cre, cph] |
| Maintainer: | Brenwin Ang <brenwinalj@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-13 07:30:15 UTC |
notionapi: Client for the 'Notion API'
Description
Enable programmatic interaction with 'Notion' pages, databases, blocks, comments, and users through the 'Notion API' https://developers.notion.com/. Provides both synchronous and asynchronous client interfaces for building workflows and automations that integrate with 'Notion' workspaces. Supports all 'Notion API' endpoints including content creation, data retrieval, and workspace management.
Author(s)
Maintainer: Brenwin Ang brenwinalj@gmail.com [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/brenwin1/notionapi/issues
R6 Class for Blocks children endpoint
Description
Handle all block children operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$blocks$children. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise block children endpoint.
Not to be called directly, e.g., use notion$pages$children instead.
Usage
BlocksChildrenEndpoint$new(client)
Arguments
clientNotion Client instance
Method list()
Retrieve a block's children
Usage
BlocksChildrenEndpoint$list(block_id, start_cursor = NULL, page_size = NULL)
Arguments
block_idString (required). The ID for a Notion block.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
Details
Method append()
Append block children
Usage
BlocksChildrenEndpoint$append(block_id, children, position = NULL)
Arguments
block_idString (required). The ID for a Notion block.
childrenList of lists (JSON array) (required). Block objects to append as children to the block.
positionNamed list (JSON object). Controls where new blocks are inserted among parent's children. Defaults to end of parent block's children when omitted.
Details
Examples
notion <- notion_client()
# ----- Append children to a block
notion$blocks$children$append(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
list(
list(
object = "block",
heading_2 = list(
rich_text = list(list(
text = list(content = "Test Heading")
))
)
)
),
position = list(type = "start")
)
# ----- Retrieve children of a block
notion$blocks$children$list("34033ea0-c1e4-81c4-afa0-d1ec98de4bec")
# ----- Iterate through paginated results
## Not run:
start_cursor <- NULL
has_more <- FALSE
resps <- list()
i <- 1
while (has_more) {
resps[[i]] <- notion$blocks$children$list(
"2926b407e3c44b49a1830609abe6744f",
start_cursor
)
has_more <- resps[[i]][["has_more"]]
start_cursor <- resps[[i]][["next_cursor"]]
i <- i + 1
}
## End(Not run)
R6 Class for Blocks Endpoint
Description
Handle all block operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$blocks. Not to be instantiated directly.
Value
A list containing the parsed API response.
Public fields
childrenBlock children endpoint
Methods
Public methods
Method new()
Initialise block endpoint.
Not to be called directly, e.g., use notion$blocks instead.
Usage
BlocksEndpoint$new(client)
Arguments
clientNotion Client instance
Method retrieve()
Retrieve a block
Usage
BlocksEndpoint$retrieve(block_id)
Arguments
block_idCharacter (required). The ID for a Notion block.
Details
Method update()
Update a block
Usage
BlocksEndpoint$update(block_id, in_trash = NULL, ...)
Arguments
block_idCharacter (required). The ID for a Notion block.
in_trashBoolean. Set to TRUE to trash (delete) a block. Set to FALSE to restore a block.
...<
dynamic-dots> Block-specific properties to update. Each argument should be named after a block type (e.g.,heading_1,paragraph) with a named list value containing the block configuration.
Details
Method delete()
Delete a block
Usage
BlocksEndpoint$delete(block_id)
Arguments
block_idCharacter (required). The ID for a Notion block.
Details
Examples
notion <- notion_client()
# ----- Retrieve a block
notion$blocks$retrieve("34033ea0-c1e4-8123-be95-e77dcc78e47d")
# ----- Update a block
notion$blocks$update(
"34033ea0-c1e4-8123-be95-e77dcc78e47d",
heading_2 = list(
rich_text = list(list(
text = list(
content = "Updated Test Heading"
)
))
)
)
# ----- Delete a block
notion$blocks$delete(
"34033ea0-c1e4-8123-be95-e77dcc78e47d"
)
R6 Class for Comments Endpoint
Description
Handle all comments operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$comments. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise comments endpoint.
Not to be called directly, e.g., use notion$comments instead.
Usage
CommentsEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a comment
Usage
CommentsEndpoint$create( rich_text, parent = NULL, discussion_id = NULL, attachments = NULL, display_name = NULL )
Arguments
rich_textList of lists (JSON array) (required). Rich text object(s) representing the content of the comment.
parentList (JSON object). The parent of the comment. This can be a page or a block. Required if
discussion_idis not provided.discussion_idCharacter. The ID of the discussion to comment on. Required if
parentis not provided.attachmentsList of lists (JSON array). An array of files to attach to the comment. Maximum of 3 allowed.
display_nameNamed list (JSON object). Display name for the comment.
Details
Method retrieve()
Retrieve comments for a block
Usage
CommentsEndpoint$retrieve(comment_id)
Arguments
comment_idCharacter (required). The ID of the comment to retrieve.
Details
Method list()
List comments
Usage
CommentsEndpoint$list(block_id, start_cursor = NULL, page_size = NULL)
Arguments
block_idCharacter (required). The ID for a Notion block or page.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
Examples
notion <- notion_client()
# ----- Create comment
notion$comments$create(
parent = list(
page_id = "34033ea0-c1e4-81c4-afa0-d1ec98de4bec"
),
rich_text = list(
list(
text = list(
content = "Hello world!"
)
)
)
)
# ----- Retrieve comment
notion$comments$retrieve("34033ea0-c1e4-8193-a220-001d29ae83c5")
# ----- List un-resolved comments from a page or block
notion$comments$list("34033ea0-c1e4-81c4-afa0-d1ec98de4bec")
R6 Class for Custom Emojis Endpoint
Description
Handle all custom emojis operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$custom_emojis. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise custom emojis endpoint.
Not to be called directly, e.g., use notion$custom_emojis instead.
Usage
CustomEmojisEndpoint$new(client)
Arguments
clientNotion Client instance
Method list()
List custom emojis
Usage
CustomEmojisEndpoint$list(start_cursor = NULL, page_size = NULL, name = NULL)
Arguments
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
nameCharacter. Filters custom emojis by exact name match. Useful for resolving a custom emoji name to its ID.
Details
Examples
notion <- notion_client()
notion$custom_emojis$list()
R6 Class for DataSources Endpoint
Description
Handle all data sources operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$datas_ources. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise data sources endpoint.
Not to be called directly, e.g., use notion$datasources instead.
Usage
DataSourcesEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a data source
Usage
DataSourcesEndpoint$create(parent, properties, title = NULL, icon = NULL)
Arguments
parentNamed list (JSON object) (required). An object specifying the parent of the new data source to be created.
propertiesNamed list (JSON object) (required). Property schema of data source.
titleList of lists (JSON array). Title of data source.
iconNamed list (JSON object). Page icon.
Details
Method retrieve()
Retrieve a data source
Usage
DataSourcesEndpoint$retrieve(data_source_id)
Arguments
data_source_idCharacter (required). ID of a Notion data source.
Details
Method list_templates()
List page templates available for a data source
Usage
DataSourcesEndpoint$list_templates( data_source_id, name = NULL, start_cursor = NULL, page_size = NULL )
Arguments
data_source_idCharacter (required). ID of a Notion data source.
nameCharacter. Name to filter templates by.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
Method update()
Update a data source
Usage
DataSourcesEndpoint$update( data_source_id, title = NULL, icon = NULL, properties = NULL, in_trash = NULL, parent = NULL )
Arguments
data_source_idCharacter (required). ID of a Notion data source.
titleList of lists (JSON array). Title of data source.
iconNamed list (JSON object). Page icon.'
propertiesNamed list (JSON object). Key-value pairs representing the data source's properties.
in_trashBoolean. Whether the database should be moved to or from the trash.
parentNamed list (JSON object). The parent of the data source, when moving it to a different database.
Method query()
Query a data source
Usage
DataSourcesEndpoint$query( data_source_id, filter_properties = NULL, sorts = NULL, filter = NULL, start_cursor = NULL, page_size = NULL, in_trash = NULL, result_type = NULL )
Arguments
data_source_idCharacter (required). ID of a Notion data source.
filter_propertiesCharacter vector. Page property value IDs to include in the response schema. If NULL (default), all properties are returned.
sortsList of lists (JSON array). Sort conditions to apply to the query
filterList of lists (JSON array). Filter conditions to apply. to the query
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
in_trashBoolean. If
TRUE, trashed pages are included in the results alongside non-trashed pages. IfFALSEorNULL(default), only non-trashed pages are returned.result_typeCharacter. Filter results by type. Available options are "page" and "data_source". If
NULL(default), all result types are returned.
Examples
notion <- notion_client()
# ----- Create a data source
notion$data_sources$create(
list(
database_id = "ffec20ee-1450-4da8-9904-f4babba0e9c0"
),
properties = list(
Title = list(
title = no_config()
)
),
title = list(list(
text = list(
content = "Test data source"
)
))
)
# ----- Update data source
notion$data_sources$update(
"34033ea0-c1e4-8112-bc3a-000bc940aa45",
properties = list(
Status = list(
status = list(
options = list(
list(
name = "To do",
color = "red"
),
list(
name = "Done",
color = "green"
)
)
)
)
)
)
# ----- Retrieve a data source
notion$data_sources$retrieve("34033ea0-c1e4-8112-bc3a-000bc940aa45")
# ----- List data source templates
notion$data_sources$list_templates("34033ea0-c1e4-8112-bc3a-000bc940aa45")
# ----- Query a data source
notion$data_sources$query(
"34033ea0-c1e4-8112-bc3a-000bc940aa45",
filter = list(
property = "Status",
status = list(
equals = "To do"
)
)
)
R6 Class for Databases Endpoint
Description
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.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise databases endpoint.
Not to be called directly, e.g., use notion$databases instead.
Usage
DatabasesEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a database
Usage
DatabasesEndpoint$create( parent, title = NULL, description = NULL, is_inline = NULL, initial_data_source = NULL, icon = NULL, cover = NULL )
Arguments
parentNamed list (JSON object) (required). The parent page or workspace where the database will be created.
titleList of lists (JSON array). The title of the database.
descriptionList of lists (JSON array). The description of the database.
is_inlineBoolean. Whether the database should be displayed inline in the parent page. Defaults to false.
initial_data_sourceNamed list (JSON object). Initial data source configuration for the database
iconNamed list (JSON object). The icon for the database.
coverNamed list (JSON object). The cover image for the database.
Details
Method retrieve()
Retrieve a database
Usage
DatabasesEndpoint$retrieve(database_id)
Arguments
database_idString (required). The ID of a Notion database.
Details
Method update()
Update a database
Usage
DatabasesEndpoint$update( database_id, parent = NULL, title = NULL, description = NULL, is_inline = NULL, icon = NULL, cover = NULL, in_trash = NULL, is_locked = NULL )
Arguments
database_idString (required). The ID of a Notion database.
parentNamed list (JSON object). The parent page or workspace to move the database to. If not provided, the database will not be moved.
titleList of lists (JSON array). The updated title of the database.
descriptionList of lists (JSON array). The updated description of the database.
is_inlineBoolean. Whether the database should be displayed in the parent page.
iconNamed list (JSON object). The updated icon for the database.
coverNamed list (JSON object). The updated cover image for the database.
in_trashBoolean. Whether the database should be moved to or from the trash.
is_lockedBoolean. Whether the database should be locked from editing.
Details
Examples
notion <- notion_client()
# ----- Create a database
notion$databases$create(
list(
type = "page_id",
page_id = "22f33ea0c1e480b99c77d1ab72aedff9"
),
title = list(list(
text = list(
content = "Test Database"
)
))
)
# ----- Retrieve a database
notion$databases$retrieve("ffec20ee-1450-4da8-9904-f4babba0e9c0")
# ----- Update a database
notion$databases$update(
"ffec20ee-1450-4da8-9904-f4babba0e9c0",
description = list(list(
text = list(
content = "For testing purposes"
)
)),
icon = list(
icon = list(
name = "calendar",
color = "gray"
)
)
)
R6 Class for File Uploads Endpoint
Description
Handle all file uploads operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$file_uploads. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise file uploads endpoint.
Not to be called directly, e.g., use notion$file_uploads instead.
Usage
FileUploadsEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a file upload
Usage
FileUploadsEndpoint$create( mode = NULL, filename = NULL, content_type = NULL, number_of_parts = NULL, external_url = NULL )
Arguments
modeCharacter. How the file is being sent. Use "multi_part" for files larger than 20MB. Use "external_url" for files that are temporarily hosted publicly elsewhere. Default is "single_part".
filenameCharacter. Name of the file to be created. Required when
modeis "multi_part". Must include an extension, or have one inferred from thecontent_typeparameter.content_typeCharacter. MIME type of the file to be created.
number_of_partsInteger. When
modeis "multi_part", the number of parts you are uploading.external_urlCharacter. When
modeis "external_url", provide the HTTPS URL of a publicly accessible file to import into your workspace.
Method send()
Upload a file
Usage
FileUploadsEndpoint$send(file_upload_id, file, part_number = NULL)
Arguments
file_upload_idCharacter (required). Identifier for a Notion file upload object.
fileNamed list (JSON object). The raw binary file contents to upload. Must contain named elements:
-
filename. Character. The name of the file, including it's extension (e.g., "report.pdf") -
data. Raw. The binary contents of the file, as returned by e.g.,readBin() -
type. Character. Optional. The MIME type of the file (e.g., "application/pdf", "image/png"). If not supplied, the type is inferred fromfilenamebycurl::form_file(). Supported file types are listed here.
-
part_numberCharacter. The current part number when uploading files greater than 20MB in parts. Must be an integer between 1 and 1,000
Method complete()
Complete a multi-part file upload
Usage
FileUploadsEndpoint$complete(file_upload_id)
Arguments
file_upload_idCharacter (required). Identifier for a Notion file upload object.
Details
Method retrieve()
Retrieve a file upload
Usage
FileUploadsEndpoint$retrieve(file_upload_id)
Arguments
file_upload_idCharacter (required). Identifier for a Notion file upload object.
Details
Method list()
List file uploads
Usage
FileUploadsEndpoint$list(status = NULL, start_cursor = NULL, page_size = NULL)
Arguments
statusCharacter. If supplied, the endpoint will return file uploads with the specified status. Available options are "pending", "uploaded", "expired", "failed".
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
Details
Examples
notion <- notion_client()
# ----- Direct upload (files <= 20MB)
# Step 1: Create a File Upload object
(resp <- notion$file_uploads$create("single_part"))
file_upload_id <- resp[["id"]]
# Step 2: Upload file contents
#* replace with your file
path <- file.path(tempdir(), "test.pdf")
writeBin(charToRaw("placeholder"), path)
raw <- readBin(path, "raw", file.size(path))
notion$file_uploads$send(
file_upload_id,
list(
filename = basename(path),
data = raw
)
)
# Retrieve the file upload
notion$file_uploads$retrieve(file_upload_id)
# ----- Multi-part upload (files > 20MB)
# Step 1: Split raw content into parts
#* replace with your file
raw <- as.raw(rep(65L, 11 * 1024 * 1024))
mid <- ceiling(length(raw) / 2)
parts <- list(raw[seq_len(mid)], raw[seq(mid + 1L, length(raw))])
# Step 2: Create a File Upload object
(resp <- notion$file_uploads$create(
mode = "multi_part",
filename = "test-large.txt",
number_of_parts = 2L
))
file_upload_id <- resp[["id"]]
# Step 3: Send each part
for (i in seq_along(parts)) {
notion$file_uploads$send(
file_upload_id,
file = list(
filename = "test-large.txt",
data = parts[[i]]
),
part_number = as.character(i)
)
}
# Step 4: Complete the upload
notion$file_uploads$complete(
file_upload_id
)
# Retrieve the file upload
notion$file_uploads$retrieve(
file_upload_id
)
# ----- Import external files
notion$file_uploads$create(
"external_url",
"dummy.pdf",
content_type = "application/pdf",
external_url = "https://github.com/brenwin1/notionapi/blob/main/tests/testthat/test.pdf"
)
R6 Class for Pages Endpoint
Description
Handle all pages operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$pages. Not to be instantiated directly.
Value
A list containing the parsed API response.
Public fields
propertiesPages properties endpoint
Methods
Public methods
Method new()
Initialise pages endpoint.
Not to be called directly, e.g., use notion$pages instead.
Usage
PagesEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a page
Usage
PagesEndpoint$create( parent, properties = NULL, icon = NULL, cover = NULL, content = NULL, children = NULL, markdown = NULL, template = NULL, position = NULL )
Arguments
parentNamed list (JSON object) (required). The parent under which the new page is created.
propertiesNamed list (JSON object). Key-value pairs representing the page's properties.
iconNamed list (JSON object). The page icon.
coverNamed list (JSON object). The page cover image.
contentList of lists (JSON array). Block objects to append as children to the page.
childrenList of lists (JSON array). Block objects to append as children to the page.
markdownCharacter. Page content as Notion-flavored Markdown. Mutually exclusive with content/children.
templateNamed list (JSON object). A data source template apply to the new page. Cannot be combined with children.
positionNamed list (JSON object). Controls where new blocks are inserted among parent's children. Defaults to end of parent block's children when omitted.
Details
Method retrieve()
Retrieve page properties
Usage
PagesEndpoint$retrieve(page_id, filter_properties = NULL)
Arguments
page_idCharacter (required). The ID for a Notion page.
filter_propertiesCharacter vector. Page property value IDs to include in the response schema. If NULL (default), all properties are returned.
Details
Method move()
Move a page
Usage
PagesEndpoint$move(page_id, parent)
Arguments
page_idCharacter (required). The ID of the page to move.
parentNamed list (JSON object) (required). The new parent location for the page.
Details
Method update()
Update attributes of a Notion page
Usage
PagesEndpoint$update( page_id, properties = NULL, icon = NULL, cover = NULL, is_locked = NULL, template = NULL, erase_content = NULL, in_trash = NULL, is_archived = NULL )
Arguments
page_idCharacter (required). The ID for a Notion page.
propertiesNamed list (JSON object). Key-value pairs representing the page's properties.
iconNamed list (JSON object). The page icon.
coverNamed list (JSON object). The page cover image.
is_lockedBoolean. Whether the page should be locked from editing.
templateNamed list (JSON object). A template to apply to the page.
erase_contentBoolean. Whether to erase all existing content from the page. Irreversible via the API.
in_trashBoolean. Set to TRUE to trash (delete) the page. Set to FALSE to restore the page.
is_archivedBoolean. Deprecated alias for
in_trash. Usein_trashfor new integrations.
Details
Method retrieve_markdown()
Retrieve a page as markdown
Usage
PagesEndpoint$retrieve_markdown(page_id, include_transcript = NULL)
Arguments
page_idCharacter (required). The ID of the page (or block) to to retrieve as markdown.
include_transcriptBoolean. Whether to include meeting note transcripts. Defaults to false.
Details
Method update_markdown()
Update a page's content as markdown
Usage
PagesEndpoint$update_markdown( page_id, type, update_content = NULL, replace_content = NULL, insert_content = NULL, replace_content_range = NULL )
Arguments
page_idCharacter (required). The ID of the page to update.
typeCharacter (required). The update command type. One of "update_content", "replace_content", "insert_content" and "replace_content_range". The first two are recommended.
update_contentNamed list (JSON object). Update specific content using search-and-replace operations.
replace_contentNamed list (JSON object). Replace the entire page content with new markdown.
insert_contentNamed list (JSON object). Insert new content into the page.
replace_content_rangeNamed list (JSON object). Replace a range of content in the page.
Details
Examples
notion <- notion_client()
# ----- Create a page
notion$pages$create(
list(page_id = "22f33ea0c1e480b99c77d1ab72aedff9"),
list(
title = list(list(
text = list(
content = "Test Page for notionapi"
)
))
)
)
# ----- Retrieve a page
notion$pages$retrieve("34033ea0-c1e4-81c4-afa0-d1ec98de4bec")
# ----- Move page into a database
notion$pages$move(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
list(
data_source_id = "34033ea0-c1e4-8112-bc3a-000bc940aa45"
)
)
# ----- Update a page
notion$pages$update(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
icon = list(
icon = list(
name = "pizza",
color = "blue"
)
)
)
# ----- Use `NA` to send JSON `null` — below removes the page's icon
notion$pages$update(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
icon = NA
)
# ----- Retrieve a page as markdown
notion$pages$retrieve_markdown("34033ea0-c1e4-81c4-afa0-d1ec98de4bec")
# ----- Update/replace a page content
notion$pages$update_markdown(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
"replace_content",
replace_content = list(
new_str = '## Updated Test Heading\nUsed markdown{color="blue"}'
)
)
# ----- Trash a page
notion$pages$update(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
in_trash = TRUE
)
R6 Class for Pages Properties Endpoint
Description
Handle all pages properties operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$pages$properties. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise pages properties endpoint.
Not to be called directly, e.g., use notion$pages$properties instead.
Usage
PagesPropertiesEndpoint$new(client)
Arguments
clientNotion Client instance
Method retrieve()
Retrieve a page property item
Usage
PagesPropertiesEndpoint$retrieve( page_id, property_id, start_cursor = NULL, page_size = NULL )
Arguments
page_idCharacter (required). The ID for a Notion page.
property_idCharacter (required). The ID of the property to retrieve.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
Details
Examples
notion <- notion_client()
# ----- Retrieve a page property
notion$pages$properties$retrieve(
"34033ea0-c1e4-81c4-afa0-d1ec98de4bec",
"%60w%5CX"
)
R6 Class for Users Endpoint
Description
Handle all users operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$users. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise users endpoint.
Not to be called directly, e.g., use notion$users instead.
Usage
UsersEndpoint$new(client)
Arguments
clientNotion Client instance
Method list()
List all users
Usage
UsersEndpoint$list(start_cursor = NULL, page_size = NULL)
Arguments
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
Details
Method retrieve()
Retrieve a user
Usage
UsersEndpoint$retrieve(user_id)
Arguments
user_idCharacter (required). The ID of the user to retrieve.
Details
Method me()
Retrieve the bot User associated with the API token
Usage
UsersEndpoint$me()
Details
Examples
notion <- notion_client()
# ----- List all users
notion$users$list()
# ----- Retrieve a user
notion$users$retrieve("fda12729-108d-4eb5-bbfb-a8f0886794d1")
# ----- Retrieve the bot User associated with the API token
notion$users$me()
R6 Class for Views Endpoint
Description
Handle all views operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$views. Not to be instantiated directly.
Value
A list containing the parsed API response.
Public fields
queriesViews Queries Endpoint
Methods
Public methods
Method new()
Initialise views endpoint.
Not to be called directly, e.g., use notion$views instead.
Usage
ViewsEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a view
Usage
ViewsEndpoint$create( data_source_id, name, type, database_id = NULL, view_id = NULL, filter = NULL, sorts = NULL, quick_filters = NULL, create_database = NULL, configuration = NULL, position = NULL, placement = NULL )
Arguments
data_source_idCharacter (required). The ID of the data source this view is scoped to.
nameCharacter (required). The name of the view.
typeCharacter (required). The type of view to create.
database_idCharacter. The ID of the database to create a view in. Mutually exclusive with
view_idandcreate_databaseview_idCharacter. The ID of a dashboard view to add this view to as a widget. Mutually exclusive with
database_idandcreate_database.filterNamed list (JSON object). Filter to apply to the view.
sortsList of lists (JSON array). Sorts to apply to the view.
quick_filtersNamed list (JSON object). Key-value pairs of quick filters to pin in the view's filter bar.
create_databaseNamed list (JSON object). Create a new linked database block and add the view to it. Mutually exclusive with
database_idandview_idconfigurationNamed list (JSON object). View presentation configuration.
positionNamed list (JSON object). Where to place the new view in the database's view tab bar. Only applicable when
database_idis provided. Defaults to "end" (append).placementNamed list (JSON object). Where to place the new widget in a dashboard view. Only applicable when
view_idis provided. Defaults to creating a new row at the end.
Details
Method retrieve()
Retrieve a view
Usage
ViewsEndpoint$retrieve(view_id)
Arguments
view_idID of a Notion view.
Details
Method update()
Update a view
Usage
ViewsEndpoint$update( view_id, name = NULL, filter = NULL, sorts = NULL, quick_filters = NULL, configuration = NULL )
Arguments
view_idID of a Notion view.
nameCharacter. New name for the view.
filterNamed list (JSON object). Filter to apply to the view.
sortsList of lists (JSON array). Property sorts to apply to the view.
quick_filtersNamed list (JSON object). Key-value pairs of quick filters to add/update.
configurationNamed list (JSON object). View presentation configuration.
Details
Method delete()
Delete a view
Usage
ViewsEndpoint$delete(view_id)
Arguments
view_idID of a Notion view.
Details
Method list()
List all views in a database
Usage
ViewsEndpoint$list( database_id = NULL, data_source_id = NULL, start_cursor = NULL, page_size = NULL )
Arguments
database_idCharacter. ID of a Notion database to list views for. At least one of
database_idordata_source_idis required.data_source_idCharacter. ID of a data source to list all views for, including linked views across the workspace. At least one of
database_idordata_source_idis required.start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
Details
Examples
notion <- notion_client()
# ----- Create a view
notion$views$create(
"34033ea0-c1e4-8112-bc3a-000bc940aa45",
"Test view",
"table",
"ffec20ee-1450-4da8-9904-f4babba0e9c0"
)
# ----- Retrieve a view
notion$views$retrieve("34033ea0-c1e4-8192-ac14-000cdad096ce")
# ----- List views
notion$views$list(data_source_id = "34033ea0-c1e4-8112-bc3a-000bc940aa45")
# ----- Update a view
notion$views$update("34033ea0-c1e4-8192-ac14-000cdad096ce", "Updated view name")
# ----- Delete a view
notion$views$delete("34033ea0-c1e4-8192-ac14-000cdad096ce")
R6 Class for Views Queries Endpoint
Description
Handle all views queries operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$views$queries. Not to be instantiated directly.
Value
A list containing the parsed API response.
Methods
Public methods
Method new()
Initialise pages properties endpoint.
Not to be called directly, e.g., use notion$views$queries instead.
Usage
ViewsQueriesEndpoint$new(client)
Arguments
clientNotion Client instance
Method create()
Create a view query
Usage
ViewsQueriesEndpoint$create(view_id, page_size = NULL)
Arguments
view_idCharacter (required). The ID of the view.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
Details
Method results()
Get view query results
Usage
ViewsQueriesEndpoint$results( view_id, query_id, start_cursor = NULL, page_size = NULL )
Arguments
view_idCharacter (required). The ID of the view.
query_idCharacter (required). The ID of the query.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
Details
Method delete()
Delete a view query
Usage
ViewsQueriesEndpoint$delete(view_id, query_id)
Arguments
view_idCharacter (required). The ID of the view.
query_idCharacter (required). The ID of the query.
Details
Examples
notion <- notion_client()
# ----- Create a view query
notion$views$queries$create("34033ea0-c1e4-8192-ac14-000cdad096ce")
# ----- Get view query results
notion$views$queries$results(
"34033ea0-c1e4-8192-ac14-000cdad096ce",
"9af03bd1-ed79-4842-a57c-0bc04fb61be2"
)
# ----- Delete a view query
notion$views$queries$delete(
"34033ea0-c1e4-8192-ac14-000cdad096ce",
"9af03bd1-ed79-4842-a57c-0bc04fb61be2"
)
Create empty property configuration
Description
Helper function that creates an empty named list for property configurations that require no additional settings.
Many database properties like text, checkbox and date
do not need configuration settings.
This function returns the empty configuration ({} in JSON)
that these properties expect.
Usage
no_config()
Value
An empty named list that serialises to {} in JSON
Examples
notion <- notion_client()
# ----- Create a data source
notion$data_sources$create(
list(
database_id = "5f9759b2-ad71-4b66-880f-d0306614227b"
),
properties = list(
Title = list(
title = no_config()
)
),
title = list(list(
text = list(
content = "Test data source"
)
))
)
Notion API client
Description
Main client for interacting with Notion API. This R6 class provides access to all Notion API endpoints through organised sub-objects.
Client Types
-
notion_client(): Create a synchronous client (blocks until requests complete) -
async_notion_client(): Create an asynchronous client (non-blocking)
Both clients provide identical interfaces, with the async client inheriting all methods from synchronous client.
The only difference is that async methods return promises instead of results directly.
Usage
notion_client(
auth = NULL,
base_url = getOption("notionapi.base_url"),
version = getOption("notionapi.version"),
timeout = 60000
)
async_notion_client(
auth = NULL,
base_url = getOption("notionapi.base_url"),
version = getOption("notionapi.version"),
timeout = 60000
)
Value
A Notion API client instance
Configuration fields
-
auth: Authentication token. Defaults to NOTION_TOKEN environment variable -
base_url: Base URL for Notion API (defaults togetOption("notionapi.base_url")) -
version: Notion API version (defaults togetOption("notionapi.version")) -
timeout: Timeout for requests in milliseconds (defaults to 60000, or 60 seconds)
Endpoints
-
blocks: Blocks endpoint object (BlocksEndpoint)-
blocks$children: Blocks children endpoint object (BlocksChildrenEndpoint)
-
-
pages: Pages endpoint object (PagesEndpoint)-
pages$properties: Pages properties endpoint object (PagesPropertiesEndpoint)
-
-
databases: Databases endpoint object (DatabasesEndpoint) -
data_sources: Data sources endpoint object (DataSourcesEndpoint) -
views: Views endpoint object (ViewsEndpoint)-
views$queries: Views queries endpoint object (ViewsQueriesEndpoint)
-
-
file_uploads: File uploads endpoint object (FileUploadsEndpoint) -
comments: Comments endpoint object (CommentsEndpoint) -
search: Search endpoint (seeNotionClient$search()method below) -
users: Users endpoint object (UsersEndpoint) -
custom_emojis: Custom emojis endpoint object (CustomEmojisEndpoint)
Public fields
base_urlBase URL for Notion API
versionNotion API version
blocksBlocks endpoint object
pagesPages endpoint object
databasesDatabases endpoint object
data_sourcesData sources endpoint object
viewsViews endpoint object
file_uploadsFile uploads endpoint object
commentsComments endpoint object
usersUsers endpoint object
custom_emojisCustom emojis endpoint object
Methods
Public methods
Method new()
Initialise Notion Client
Usage
NotionClient$new(
auth = NULL,
base_url = getOption("notionapi.base_url"),
version = getOption("notionapi.version"),
timeout = 60000
)Arguments
authAuthentication token. Uses NOTION_TOKEN environment variable by default.
base_urlCharacter. Base URL for Notion API.
versionCharacter. Notion API version.
timeoutNumeric. Number of milliseconds to wait before timing out a request.
Method request()
Create a base httr2 request object for the Notion API.
This method is primarily for advanced users who want to make custom API calls or for debugging purposes. Most users should use the endpoint methods instead.
Usage
NotionClient$request()
Returns
httr2 request object
Method print()
Print basic details of Notion Client
Usage
NotionClient$print()
Method search()
Search all parent or child pages and databases shared with an integration
Usage
NotionClient$search( sort = NULL, query = NULL, start_cursor = NULL, page_size = NULL, filter = NULL )
Arguments
sortNamed list (JSON object). Sort condition to apply to the search results.
queryCharacter. The search query string.
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100.
filterList (JSON object). Filter condition to apply to the search results.
Details
Super class
notionapi::NotionClient -> AsyncNotionClient
Methods
Public methods
Inherited methods
Method new()
Initialise Async Notion Client
Usage
AsyncNotionClient$new(
auth = NULL,
base_url = getOption("notionapi.base_url"),
version = getOption("notionapi.version"),
timeout = 60000
)Arguments
authAuthentication token. Uses NOTION_TOKEN environment variable by default.
base_urlCharacter. Base URL for Notion API.
versionCharacter. Notion API version.
timeoutNumeric. Number of milliseconds to wait before timing out a request.
Method request()
Create a base httr2 request object for the Notion API.
This method is primarily for advanced users who want to make custom API calls or for debugging purposes. Most users should use the endpoint methods instead.
Usage
AsyncNotionClient$request()
Returns
httr2 request object
Method print()
Print basic details of Notion Client
Usage
AsyncNotionClient$print()
See Also
Examples
# ----- Create a Notion client with default configuration
notion <- notion_client()
# ----- Search for pages and databases
notion$search(
query = "Test Page for notionapi",
page_size = 1,
filter = list(
property = "object",
value = "page"
),
sort = list(
timestamp = "last_edited_time",
direction = "descending"
)
)
# ----- Async client
## Not run:
library(promises)
async_notion <- async_notion_client()
# Start multiple requests simultaneously (non-blocking)
p1 <- async_notion$search(
query = "Testing",
page_size = 1
)
p2 <- async_notion$users$me()
# Returns a promise object, not particularly useful on its own
p1
p2
# Use promise chaining functions to process results as they complete
p1 %...>%
print()
p2 %...>%
print()
# See the [promises package documentation](https://rstudio.github.io/promises/)
# for more information on working with promises
## End(Not run)
Check if Notion token is set
Description
Checks if the NOTION_TOKEN environment variable is set.
Usage
notion_token_exists()
Value
TRUE if the token exists, FALSE otherwise.
Examples
notion_token_exists()
Print the result of a Notion API call
Description
Print the result of a Notion API call
Usage
## S3 method for class 'notion_response'
print(x, ...)
Arguments
x |
The result object. |
... |
Ignored. |
Value
The JSON result.
VCR Example Helpers
Description
Internal functions for managing VCR cassettes in package examples. These functions are not intended for direct use by package users.
Usage
vcr_example_start(name)
vcr_example_end()
Arguments
name |
Character. The name of the cassette to be used. |