Modules@robinpath/notion
notion

@robinpath/notion

0.1.2Node.jsPublic

Notion module for RobinPath.

Notion

Notion module for RobinPath.

Package: @robinpath/notion | Category: Productivity | Type: Integration

Authentication

notion.setToken "ntn_xxx"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the notion module when you need to:

  • Retrieve a Notion page by ID. -- Use notion.getPage to perform this operation
  • Create a new page in a database or as a child of another page. -- Use notion.createPage to perform this operation
  • Update properties of an existing page. -- Use notion.updatePage to perform this operation
  • Archive (soft-delete) a Notion page. -- Use notion.archivePage to perform this operation
  • Query a Notion database with optional filters and sorts. -- Use notion.queryDatabase to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenSet the Notion integration token.Confirmation message.
getPageRetrieve a Notion page by ID.Page object with properties.
createPageCreate a new page in a database or as a child of another page.Created page object.
updatePageUpdate properties of an existing page.Updated page object.
archivePageArchive (soft-delete) a Notion page.Archived page object.
queryDatabaseQuery a Notion database with optional filters and sorts.Query results with results array.
getDatabaseRetrieve a Notion database schema.Database object with properties schema.
getBlocksGet child blocks of a page or block.List of child block objects.
appendBlocksAppend child blocks to a page or block.Appended blocks response.
deleteBlockDelete a block by ID.Deleted block object.
searchSearch across all pages and databases the integration has access to.Search results.

Functions

setToken

Set the Notion integration token.

Module: notion | Returns: string -- Confirmation message.

notion.setToken "ntn_xxx"
ParameterTypeRequiredDescription
tokenstringYesNotion internal integration token

getPage

Retrieve a Notion page by ID.

Module: notion | Returns: object -- Page object with properties.

notion.getPage "page-id-here"
ParameterTypeRequiredDescription
pageIdstringYesThe page ID

createPage

Create a new page in a database or as a child of another page.

Module: notion | Returns: object -- Created page object.

notion.createPage "db-id" {"Name":{"title":[{"text":{"content":"New Page"}}]}}
ParameterTypeRequiredDescription
parentIdstringYesParent database or page ID
propertiesobjectYesPage properties object
optionsobjectNoOptions: parentType ('database'

updatePage

Update properties of an existing page.

Module: notion | Returns: object -- Updated page object.

notion.updatePage "page-id" {"Status":{"select":{"name":"Done"}}}
ParameterTypeRequiredDescription
pageIdstringYesThe page ID
propertiesobjectYesProperties to update

archivePage

Archive (soft-delete) a Notion page.

Module: notion | Returns: object -- Archived page object.

notion.archivePage "page-id"
ParameterTypeRequiredDescription
pageIdstringYesThe page ID to archive

queryDatabase

Query a Notion database with optional filters and sorts.

Module: notion | Returns: object -- Query results with results array.

notion.queryDatabase "db-id" {"filter":{"property":"Status","select":{"equals":"Active"}}}
ParameterTypeRequiredDescription
databaseIdstringYesThe database ID
optionsobjectNoQuery options: filter, sorts, start_cursor, page_size

getDatabase

Retrieve a Notion database schema.

Module: notion | Returns: object -- Database object with properties schema.

notion.getDatabase "db-id"
ParameterTypeRequiredDescription
databaseIdstringYesThe database ID

getBlocks

Get child blocks of a page or block.

Module: notion | Returns: object -- List of child block objects.

notion.getBlocks "page-id"
ParameterTypeRequiredDescription
blockIdstringYesPage or block ID

appendBlocks

Append child blocks to a page or block.

Module: notion | Returns: object -- Appended blocks response.

notion.appendBlocks "page-id" [{"type":"paragraph","paragraph":{"rich_text":[{"text":{"content":"Hello"}}]}}]
ParameterTypeRequiredDescription
blockIdstringYesPage or block ID
childrenarrayYesArray of block objects to append

deleteBlock

Delete a block by ID.

Module: notion | Returns: object -- Deleted block object.

notion.deleteBlock "block-id"
ParameterTypeRequiredDescription
blockIdstringYesThe block ID to delete

search

Search across all pages and databases the integration has access to.

Module: notion | Returns: object -- Search results.

notion.search "meeting notes"
ParameterTypeRequiredDescription
querystringNoSearch query text
optionsobjectNoOptions: filter, sort, start_cursor, page_size

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Notion: token not configured. Call notion.setToken first.Check the error message for details
Notion API error (${res.status}): ${text}Check the error message for details
notion.setToken requires a token.Check the error message for details
notion.getPage requires a pageId.Check the error message for details
notion.createPage requires parentId and properties.Check the error message for details
notion.updatePage requires pageId and properties.Check the error message for details
notion.archivePage requires a pageId.Check the error message for details
notion.queryDatabase requires a databaseId.Check the error message for details
@desc "Get page and validate result"
do
  set $result as notion.getPage "page-id-here"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Page

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Get page and iterate results"
do
  set $result as notion.getPage "page-id-here"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createPage

Create a new resource and capture the result.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Create page"
do
  set $result as notion.createPage "db-id" {"Name":{"title":[{"text":{"content":"New Page"}}]}}
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Create page and update page"
do
  set $created as notion.createPage "db-id" {"Name":{"title":[{"text":{"content":"New Page"}}]}}
  # Update the created item
  notion.updatePage "page-id" {"Status":{"select":{"name":"Done"}}}
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Get page and create page"
do
  set $existing as notion.getPage "page-id-here"
  if $existing == null
    notion.createPage "db-id" {"Name":{"title":[{"text":{"content":"New Page"}}]}}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Notion workflow

Chain multiple notion operations together.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Get page, create page, and more"
do
  set $r_getPage as notion.getPage "page-id-here"
  set $r_createPage as notion.createPage "db-id" {"Name":{"title":[{"text":{"content":"New Page"}}]}}
  set $r_updatePage as notion.updatePage "page-id" {"Status":{"select":{"name":"Done"}}}
  print "All operations complete"
enddo

6. Safe getPage with validation

Check results before proceeding.

@desc "Setup authentication"
do
  notion.setToken $token
enddo

@desc "Get page and validate result"
do
  set $result as notion.getPage "page-id-here"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • google-sheets -- Google Sheets module for complementary functionality
  • google-calendar -- Google Calendar module for complementary functionality
  • google-contacts -- Google Contacts module for complementary functionality
  • google-forms -- Google Forms module for complementary functionality
  • gmail -- Gmail module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/notion

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size5.4 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

productivity