[PARAM(optional)] dry_run:
true if you want to create a verification script (Boolean)
[EXCEPTION] StandardError
throw StandardError when the data_source is not found.
DataSource.find(id) creates a DataSource object with retrieving data source API. The created object has data source information generated from the JSON response.
DataSource.find id, dry_run: true creates shell script using Retrieve a data source API for verification.
2. Instance methods
add_property(klass, title)
[PARAM] klass
klass (child class of Property)
[PARAM] title
property title (String)
add_property adds a data source property. After setting the property, please call ds.save to send data source information to Notion.
ds.save dry_run: true creates a shell script for verification (Update data source API using data_source_id as parent)
build_child_page creates a child page object of the data source. 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 data source. 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. By setting the template_page option, you can apply a template when creating a page. The value is either the string "default" or a Page object of the retrieved template page.
page.save dry_run: true creates a shell script for verification (Create a page API using data_source_id as parent)
create_child_page creates a child page object of the data source and send to Notion. Properties of the created child page are automatically assigned using the parent data source. 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. By setting the template_page option, you can apply a template when creating a page. The value is either the string "default" or a Page object of the retrieved template page.
create_child_page dry_run: true creates a shell script for verification (Create a page API using data_source_id as parent)
created_time → CreatedTimeProperty
created_time returns the CreatedTimeProperty object for querying data source.
data_source_title → RichTextArray
data_source_title returns a RichTextArray object of the data source’s title.
description → RichTextArray
description returns a RichTextArray object of the data source’s description.
description=(text_info)
[PARAM] text_info
📃
The following objects are used for this argument.
a String like as “text” (String)
an Array of Strings (Array of Strings)
a RichTextObject (RichTextObject)
an Array of RichTextObjects (Array of RichTextObjects)
a RichTextArray (RichTextArray)
description=(text_info) updates the data source description using a text_info.
is_inline → Boolean
is_inline returns the value true if the data source appears in the page as an inline block.
is_inline=(flag)
is_inline=(flag) updates the data source inline flag a flag value.
icon → Hash
icon returns JSON hash for the page icon.
last_edited_time → LastEditedTimeProperty
last_edited_time returns the LastEditedTimeProperty object for querying data source.
new_record? → Boolean, NilClass
new_record? returns true if the page is generated by create_child_data_source.
properties → PropertyCache
properties returns a PropertyCache object. Each DataSource property object can be obtained from PropertyCache object by [] method.
query_data_source(query = nil, dry_run: false) → List
[PARAM(optional)] query
Query object including filter conditions and sort criteria. If no query is given, all pages are retrieved. (Query)
[PARAM(optional)] dry_run:
true if you want to create a verification script (Boolean)
A: overview
ds.query_data_source obtains a List object with Page objects contained in the data source. You can obtain filtered and ordered pages using Query object.
The query object can be generated from the Property objects included in the data source object. The Property object can be obtained from the retrieved or assigned data source object like as the Page object.
filter_xxxx methods of the property objects generates a query object. These methods are explained in the section of each property object class.
B: complex conditions
Complex filters can be generated and / or methods of the Query object. Here are some sample scripts and the json parameters created from them.
query1: (A and B) filter
query2: (A and B and C) filter
query3: (A or B) filter
query4: (A or B or C) filter
query5: ((A and B) or C) filter
query6: ((A or B) and C) filter
query7: ((A and B) or (C and D)) filter
C: Sort criteria
Sort criteria can be appended to an existing query object. If you don't use the previous filters, you can generate by Query.new.
sort criteria only
filter with sort
D: Dry run sample
This is a sample script for query data source. If dry_run flag is set, you can see the verification shell script.
remove_properties(*property_names) → Array
[PARAM] property_names:
property names that you want to remove
remove_properties sets a remove flag for the property objects corresponding to the specified names. After setting the remove flags of some properties, please call ds.save to send data source information to Notion.
rename_property sets a rename flag for the property objects corresponding to the specified old name. After setting the rename flags of some properties, please call ds.save to send data source information to Notion.
ds = DataSource.find "26cd8e4e98ab81d08983000b28d9e04d" # Notion API call
ds.add_property NumberProperty, "added number property" do |np|
np.format = "euro" # arrange option
end
ds.add_property UrlProperty, "added url property" # UrlProperty has no option
ds.save
# => NotionRubyMapping::DataSource-26cd8e4e98ab81d08983000b28d9e04d
ds = DataSource.find "26cd8e4e98ab81d08983000b28d9e04d" # Notion API call
ds.add_property NumberProperty, "added number property" do |np|
np.format = "euro" # arrange option
end
ds.add_property UrlProperty, "added url property" # UrlProperty has no option
print ds.save dry_run: true
# #!/bin/sh
# curl -X PATCH 'https://api.notion.com/v1/data_sources/26cd8e4e98ab81d08983000b28d9e04d''' \
# -H 'Notion-Version: 2025-09-03' \
# -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
# -H 'Content-Type: application/json' \
# --data '{"properties":{"added number property":{"number":{"format":"euro"}},"added url property":{"url":{}}}}'
# => nil
page = ds.build_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)
page = ds.build_child_page(template_page: "default") 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)
template_page = Page.find "template_page_id"
page = ds.build_child_page(template_page: tempalte_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)
page = ds.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
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)
page = ds.create_child_page(template_page: "default") 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
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)
template_page = Page.find "template_page_id"
page = ds.create_child_page(template_page: template_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
# => #<NotionRubyMapping::Page:...> # Page object generated from response from Notion (created Page)