notionapi is an R client library for Notion API, enabling users to programmatically interact with their Notion workspaces. The package provides complete API coverage for managing pages and databases, managing content blocks, handling comments and retrieving user information.
The package is designed to mirror the Official Notion JavaScript Client, using R6 classes to provide a familiar object-oriented interface and consistent API structure.
Install the package from CRAN:
install.packages("notionapi")
Or install the development version from GitHub:
::pak("brenwin1/notionapi") pak
To initialise the Notion client, you need a Notion integration token.
Create an integration in your Notion workspace following these instructions.
Copy the integration token from your integration settings.
Set the token as an environment variable:
::edit_r_environ()
usethis# add NOTION_TOKEN=<your_integration_token>
Share pages/databases with your integration in Notion.
Restart your R session to load the environment variable.
Use notion_client()
or
async_notion_client()
to create a client instance for
accessing the API endpoints:
The client organises methods into logical endpoint groups like pages, databases, and blocks. Each method maps directly to an endpoint, with parameters available as function arguments.
See the Notion API reference for complete endpoint documentation.
library(notionapi)
# Create a Notion client instance
<- notion_client()
notion
# Access the users endpoint to list all users in your Notion workspace
<- notion$users$list()
resp
resp#> {
#> "object": "list",
#> "results": [
#> {
#> "object": "user",
#> "id": "fda12729-108d-4eb5-bbfb-a8f0886794d1",
#> "name": "Brenwin",
#> "avatar_url": {},
#> "type": "person",
#> "person": {}
#> },
#> {
#> "object": "user",
#> "id": "6b786605-e456-4237-9c61-5efaff23c081",
#> "name": "brenwin-internal",
#> "avatar_url": {},
#> "type": "bot",
#> "bot": {
#> "owner": {
#> "type": "workspace",
#> "workspace": true
#> },
#> "workspace_name": "Brenwin's Notion",
#> "workspace_limits": {
#> "max_file_upload_size_in_bytes": 5368709120
#> }
#> }
#> }
#> ],
#> "next_cursor": {},
#> "has_more": false,
#> "type": "user",
#> "user": {},
#> "request_id": "7ecade3d-9ad8-4a02-bd8d-9aee421e18c6"
#> }
API responses are automatically converted from JSON to R lists.
# Extract specific fields from the response (list subsetting)
vapply(resp$results, "[[", "", "type")
#> [1] "person" "bot"
R data structures are automatically converted to the JSON format expected by the Notion API:
lists
→ JSON objectlist of lists
→ JSON arrayExamples are provided throughout the reference documentation. See CommentsEndpoint create() method for an example.
See Pagination section in Notion API documentation for supported endpoints and implementation details.
Pagination parameters (page_size
and
start_cursor
) are exposed as function arguments.
For an example, see BlocksChildrenEndpoint retrieve() method.