<aside> 👉 Links (Block base class)

Page

BookmarkBlock

CodeBlock

EmbedBlock

Heading2Block

LinkToPageBlock

QuoteBlock

ToDoBlock

ToggleHeading3Block

Database

List

BulletedListItemBlock

ColumnListBlock

FileBlock

ImageBlock

ParagraphBlock

TableOfContentsBlock

ToggleHeading1Block

Block

CalloutBlock

DividerBlock

Heading1Block

LinkPreviewBlock

PdfBlock

TemplateBlock

ToggleHeading2Block

Notion Ruby Mapping Public API Reference

</aside>

<aside> ℹī¸ ↑ Table of Contents

</aside>

1. Singleton methods

self.find(id, dry_run: false)

Database.find(id) creates a Database object with retrieving database API. The created object has database information generated from the JSON response.

Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253" # Notion API call
# => #<NotionRubyMapping::Database:...> # retrieved Database object

Database.find id, dry_run: true creates shell script using Retrieve a database API for verification.

Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253", dry_run: true
# =>
# #!/bin/sh
# curl  '<https://api.notion.com/v1/databases/c37a2c66-e3aa-4a0d-a447-73de3b80c253>'\\\\
#   -H 'Notion-Version: 2022-02-22'\\\\
#   -H 'Authorization: Bearer '"$NOTION_API_KEY"''\\\\
#   -H 'Content-Type: application/json'

↑ Table of Contents

2. Instance methods

add_property(klass, title)

add_property adds a database property. After setting the property, please call db.save to send database information to Notion.

db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
db.add_property NumberProperty, "added number property" do |np|
  np.format = "euro" # arrange option
end
db.add_property UrlProperty, "added url property" # UrlProperty has no option
db.save
# => #<NotionRubyMapping::Database:...> # updated Database object

db.save dry_run: true creates a shell script for verification (Update database API using database_id as parent)

db = Database.find "c7697137d49f49c2bbcdd6a665c4f921"
db.add_property NumberProperty, "added number property" do |np|
  np.format = "euro" # arrange option
end
db.add_property UrlProperty, "added url property" # UrlProperty has no option
db.save dry_run: true
# =>
# #!/bin/sh
# curl -X PATCH '<https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f921>'\\\\
#   -H 'Notion-Version: 2022-02-22'\\\\
#   -H 'Authorization: Bearer '"$NOTION_API_KEY"''\\\\
#   -H 'Content-Type: application/json'\\\\
#   --data '{"properties":{"added number property":{"number":{"format":"euro"}},"added url property":{"url":{}}}}'

↑ Table of Contents

build_child_page { |p, pc| ... } → Page

<aside> 💡 [Breaking change on v0.4.0] For compatibility with Rails, create_child_page is renamed to build_child_page. create_child_page calls build_child_page and save.

</aside>

build_child_page creates a child page object of the database. After setting some properties, please call page.save to send page information to Notion. Properties of the created child page are automatically assigned using the parent database. if a block is provided, the method will yield the new Page object(p) and the properties (PropertyCache object pc) to that block for initialization.

page = db.create_child_page do |p, pc|
  # p is the new Page object
  # pc is the properties of the new Page object (PropertyCache Object)
  p.set_icon emoji: "🎉"
  pc["Title"] << "New Page"
end
page.save
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)