notionrb 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/Dockerfile +5 -0
  3. data/.devcontainer/boot.sh +1 -0
  4. data/.devcontainer/devcontainer.json +30 -0
  5. data/.github/workflows/ci.yml +15 -0
  6. data/.github/workflows/rubocop.yml +17 -0
  7. data/.gitignore +7 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +55 -0
  10. data/.rubocop_todo.yml +86 -0
  11. data/CHANGELOG.md +144 -0
  12. data/CODE_OF_CONDUCT.md +128 -0
  13. data/CONTRIBUTING.md +51 -0
  14. data/Gemfile +4 -0
  15. data/Gemfile.lock +95 -0
  16. data/LICENSE.md +21 -0
  17. data/README.md +677 -0
  18. data/Rakefile +18 -0
  19. data/bin/console +31 -0
  20. data/lib/notion/api/endpoints/blocks.rb +100 -0
  21. data/lib/notion/api/endpoints/comments.rb +61 -0
  22. data/lib/notion/api/endpoints/data_sources.rb +102 -0
  23. data/lib/notion/api/endpoints/databases.rb +134 -0
  24. data/lib/notion/api/endpoints/pages.rb +95 -0
  25. data/lib/notion/api/endpoints/search.rb +41 -0
  26. data/lib/notion/api/endpoints/users.rb +48 -0
  27. data/lib/notion/api/endpoints.rb +23 -0
  28. data/lib/notion/api/error.rb +6 -0
  29. data/lib/notion/api/errors/internal_error.rb +12 -0
  30. data/lib/notion/api/errors/notion_error.rb +15 -0
  31. data/lib/notion/api/errors/too_many_requests.rb +15 -0
  32. data/lib/notion/api/errors.rb +23 -0
  33. data/lib/notion/client.rb +28 -0
  34. data/lib/notion/config.rb +54 -0
  35. data/lib/notion/faraday/connection.rb +37 -0
  36. data/lib/notion/faraday/request.rb +45 -0
  37. data/lib/notion/faraday/response/raise_error.rb +31 -0
  38. data/lib/notion/faraday/response/wrap_error.rb +22 -0
  39. data/lib/notion/logger.rb +14 -0
  40. data/lib/notion/messages/message.rb +17 -0
  41. data/lib/notion/pagination/cursor.rb +53 -0
  42. data/lib/notion/version.rb +5 -0
  43. data/lib/notion-ruby-client.rb +28 -0
  44. data/lib/notion.rb +2 -0
  45. data/lib/notion_ruby_client.rb +2 -0
  46. data/notionrb.gemspec +31 -0
  47. data/spec/fixtures/notion/block.yml +146 -0
  48. data/spec/fixtures/notion/block_append_children.yml +149 -0
  49. data/spec/fixtures/notion/block_children.yml +152 -0
  50. data/spec/fixtures/notion/create_data_source.yml +29 -0
  51. data/spec/fixtures/notion/create_database.yml +149 -0
  52. data/spec/fixtures/notion/create_discussion_comment.yml +110 -0
  53. data/spec/fixtures/notion/create_page.yml +152 -0
  54. data/spec/fixtures/notion/create_page_comment.yml +110 -0
  55. data/spec/fixtures/notion/create_page_with_data_source.yml +29 -0
  56. data/spec/fixtures/notion/create_page_with_parent_page.yml +128 -0
  57. data/spec/fixtures/notion/data_source.yml +27 -0
  58. data/spec/fixtures/notion/data_source_query.yml +29 -0
  59. data/spec/fixtures/notion/database.yml +150 -0
  60. data/spec/fixtures/notion/database_query.yml +154 -0
  61. data/spec/fixtures/notion/delete_block.yml +145 -0
  62. data/spec/fixtures/notion/page.yml +150 -0
  63. data/spec/fixtures/notion/page_property_item.yml +143 -0
  64. data/spec/fixtures/notion/paginated_block_children.yml +575 -0
  65. data/spec/fixtures/notion/paginated_data_source_query.yml +29 -0
  66. data/spec/fixtures/notion/paginated_database_query.yml +152 -0
  67. data/spec/fixtures/notion/paginated_databases_list.yml +150 -0
  68. data/spec/fixtures/notion/paginated_search.yml +301 -0
  69. data/spec/fixtures/notion/paginated_users_list.yml +146 -0
  70. data/spec/fixtures/notion/retrieve_comments.yml +106 -0
  71. data/spec/fixtures/notion/search.yml +160 -0
  72. data/spec/fixtures/notion/search_with_query.yml +152 -0
  73. data/spec/fixtures/notion/update_block.yml +148 -0
  74. data/spec/fixtures/notion/update_data_source.yml +29 -0
  75. data/spec/fixtures/notion/update_database.yml +152 -0
  76. data/spec/fixtures/notion/update_page.yml +152 -0
  77. data/spec/fixtures/notion/users.yml +145 -0
  78. data/spec/fixtures/notion/users_list.yml +146 -0
  79. data/spec/fixtures/notion/users_me.yml +144 -0
  80. data/spec/notion/api/endpoints/blocks_spec.rb +72 -0
  81. data/spec/notion/api/endpoints/comments_spec.rb +49 -0
  82. data/spec/notion/api/endpoints/data_sources_spec.rb +61 -0
  83. data/spec/notion/api/endpoints/databases_spec.rb +70 -0
  84. data/spec/notion/api/endpoints/pages_spec.rb +127 -0
  85. data/spec/notion/api/endpoints/search_spec.rb +26 -0
  86. data/spec/notion/api/endpoints/users_spec.rb +31 -0
  87. data/spec/notion/config_spec.rb +16 -0
  88. data/spec/notion/pagination/cursor_spec.rb +126 -0
  89. data/spec/notion/version_spec.rb +8 -0
  90. data/spec/spec_helper.rb +22 -0
  91. data/spec/support/token.rb +10 -0
  92. data/spec/support/vcr.rb +16 -0
  93. metadata +358 -0
data/README.md ADDED
@@ -0,0 +1,677 @@
1
+ # Notion Ruby Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/notion-ruby-client.svg)](http://badge.fury.io/rb/notion-ruby-client)
4
+ [![CI workflow badge](https://github.com/phacks/notion-ruby-client/actions/workflows/ci.yml/badge.svg)](https://github.com/phacks/notion-ruby-client/actions/workflows/ci.yml)
5
+
6
+ A Ruby client for the Notion API.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Create a New Bot Integration](#create-a-new-bot-integration)
13
+ - [Declare the API token](#declare-the-api-token)
14
+ - [API Client](#api-client)
15
+ - [Instantiating a new Notion API client](#instantiating-a-new-notion-api-client)
16
+ - [Pagination](#pagination)
17
+ - [Endpoints](#endpoints)
18
+ - [Databases](#databases)
19
+ - [Query a database](#query-a-database)
20
+ - [Create a Database](#create-a-database)
21
+ - [Update a Database](#update-a-database)
22
+ - [Retrieve a database](#retrieve-a-database)
23
+ - [Pages](#pages)
24
+ - [Retrieve a page](#retrieve-a-page)
25
+ - [Create a page](#create-a-page)
26
+ - [Update page](#update-page)
27
+ - [Retrieve a page property item](#retrieve-a-page-property-item)
28
+ - [Blocks](#blocks)
29
+ - [Retrieve a block](#retrieve-a-block)
30
+ - [Update a block](#update-a-block)
31
+ - [Delete a block](#delete-a-block)
32
+ - [Retrieve block children](#retrieve-block-children)
33
+ - [Append block children](#append-block-children)
34
+ - [Comments](#comments)
35
+ - [Retrieve comments](#retrieve-comments-from-a-page-or-block-by-id)
36
+ - [Create a comment on a page](#create-a-comment-on-a-page)
37
+ - [Create a comment on a discussion](#create-a-comment-on-a-discussion)
38
+ - [Users](#users)
39
+ - [Retrieve your token's bot user](#retrieve-your-tokens-bot-user)
40
+ - [Retrieve a user](#retrieve-a-user)
41
+ - [List all users](#list-all-users)
42
+ - [Search](#search)
43
+ - [Acknowledgements](#acknowledgements)
44
+
45
+ ## Installation
46
+
47
+ Add to Gemfile.
48
+
49
+ ```
50
+ gem 'notion-ruby-client'
51
+ ```
52
+
53
+ Run `bundle install`.
54
+
55
+ ## Usage
56
+
57
+ ### Create a New Integration
58
+
59
+ > :blue_book: **Before you start**
60
+ >
61
+ > Make sure you are an **Admin** user in your Notion workspace. If you're not an Admin in your current workspace, [create a new personal workspace for free](https://www.notion.so/notion/Create-join-switch-workspaces-3b9be78982a940a7a27ce712ca6bdcf5#9332861c775543d0965f918924448a6d).
62
+
63
+ To create a new integration, follow the steps 1 & 2 outlined in the [Notion documentation](https://developers.notion.com/docs#getting-started). The “_Internal Integration Token_” is what is going to be used to authenticate API calls (referred to here as the “API token”).
64
+
65
+ > :blue_book: Integrations don't have access to any pages (or databases) in the workspace at first. **A user must share specific pages with an integration in order for those pages to be accessed using the API.**
66
+
67
+ ### Declare the API token
68
+
69
+ ```ruby
70
+ Notion.configure do |config|
71
+ config.token = ENV['NOTION_API_TOKEN']
72
+ end
73
+ ```
74
+
75
+ For Rails projects, the snippet above would go to `config/application.rb`.
76
+
77
+ ### API Client
78
+
79
+ #### Instantiating a new Notion API client
80
+
81
+ ```ruby
82
+ client = Notion::Client.new
83
+ ```
84
+
85
+ You can specify the token or logger on a per-client basis:
86
+
87
+ ```ruby
88
+ client = Notion::Client.new(token: '<secret Notion API token>')
89
+ ```
90
+
91
+ #### Pagination
92
+
93
+ The client natively supports [cursor pagination](https://developers.notion.com/reference/pagination) for methods that allow it, such as `users_list`. Supply a block and the client will make repeated requests adjusting the value of `start_cursor` with every response. The default page size is set to 100 (Notion’s current default and maximum) and can be adjusted via `Notion::Client.config.default_page_size` or by passing it directly into the API call.
94
+
95
+ ```ruby
96
+ all_users = []
97
+ client.users_list(page_size: 25) do |page|
98
+ all_users.concat(page.results)
99
+ end
100
+ all_users # All users, retrieved 25 at a time
101
+ ```
102
+
103
+ When using cursor pagination the client will automatically pause and then retry the request if it runs into [Notion rate limiting](https://developers.notion.com/reference/errors#request-limits). (It will pause for 10 seconds before retrying the request, a value that can be overriden with `Notion::Client.config.default_retry_after`.) If it receives too many rate-limited responses in a row it will give up and raise an error. The default number of retries is 100 and can be adjusted via `Notion::Client.config.default_max_retries` or by passing it directly into the method as `max_retries`.
104
+
105
+ You can also proactively avoid rate limiting by adding a pause between every paginated request with the `sleep_interval` parameter, which is given in seconds.
106
+
107
+ ```ruby
108
+ all_users = []
109
+ client.users_list(sleep_interval: 5, max_retries: 20) do |page|
110
+ # pauses for 5 seconds between each request
111
+ # gives up after 20 consecutive rate-limited responses
112
+ all_users.concat(page.results)
113
+ end
114
+ all_users
115
+ ```
116
+
117
+ ## Endpoints
118
+
119
+ ### Databases
120
+
121
+ As of `Notion-Version` `2025-09-03`, a database can hold multiple **data sources**, and querying, and property-schema changes are performed against a data source, not the database itself. Use [`database`](#retrieve-a-database) to look up a database's data source ids, then see [Data sources](#data-sources) below. `database_query` is kept for reference but the underlying endpoint is deprecated — use [`data_source_query`](#query-a-data-source) instead.
122
+
123
+ #### Query a database (deprecated)
124
+
125
+ Gets a paginated array of [Page](https://developers.notion.com/reference/page) objects contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request.
126
+
127
+ ```ruby
128
+ client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') # retrieves the first page
129
+
130
+ client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
131
+
132
+ client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') do |page|
133
+ # paginate through all pages
134
+ end
135
+
136
+ # Filter and sort the database
137
+ sorts = [
138
+ {
139
+ 'timestamp': 'created_time',
140
+ 'direction': 'ascending'
141
+ }
142
+ ]
143
+ filter = {
144
+ 'or': [
145
+ {
146
+ 'property': 'In stock',
147
+ 'checkbox': {
148
+ 'equals': true
149
+ }
150
+ },
151
+ {
152
+ 'property': 'Cost of next trip',
153
+ 'number': {
154
+ 'greater_than_or_equal_to': 2
155
+ }
156
+ }
157
+ ]
158
+ }
159
+ client.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', sorts: sorts, filter: filter)
160
+ ```
161
+
162
+ See [Pagination](#pagination) for details about how to iterate through the list.
163
+
164
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-database-query).
165
+
166
+ #### Create a Database
167
+
168
+ Creates a database, with a single data source, as a subpage in the specified parent page, with the specified properties schema.
169
+
170
+ ```ruby
171
+ title = [
172
+ {
173
+ 'type': 'text',
174
+ 'text': {
175
+ 'content': 'Grocery List',
176
+ 'link': nil
177
+ }
178
+ }
179
+ ]
180
+ properties = {
181
+ 'Name': {
182
+ 'title': {}
183
+ },
184
+ 'Description': {
185
+ 'rich_text': {}
186
+ },
187
+ 'In stock': {
188
+ 'checkbox': {}
189
+ },
190
+ 'Food group': {
191
+ 'select': {
192
+ 'options': [
193
+ {
194
+ 'name': '🥦Vegetable',
195
+ 'color': 'green'
196
+ },
197
+ {
198
+ 'name': '🍎Fruit',
199
+ 'color': 'red'
200
+ },
201
+ {
202
+ 'name': '💪Protein',
203
+ 'color': 'yellow'
204
+ }
205
+ ]
206
+ }
207
+ }
208
+ }
209
+ client.create_database(
210
+ parent: { page_id: '98ad959b-2b6a-4774-80ee-00246fb0ea9b' },
211
+ title: title,
212
+ properties: properties
213
+ )
214
+ ```
215
+
216
+ > Under the hood, the Notion API now expects the schema nested under `initial_data_source: { properties: ... }`. The `properties:` shorthand above is still accepted and wrapped automatically; you can also pass `initial_data_source:` directly.
217
+
218
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/create-database).
219
+
220
+ #### Update a Database
221
+
222
+ Updates an existing database as specified by the parameters. As of `2025-09-03` this only covers database-level fields (`title`, `description`, `icon`, `cover`, `is_inline`, `in_trash`, `is_locked`, `parent`) — use [`update_data_source`](#update-a-data-source) to change the property schema.
223
+
224
+ ```ruby
225
+ title = [
226
+ {
227
+ 'text': {
228
+ 'content': 'Orbit 💜 Notion'
229
+ }
230
+ }
231
+ ]
232
+ client.update_database(database_id: 'dd428e9dd3fe4171870da7a1902c748b', title: title)
233
+ ```
234
+
235
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/update-database).
236
+
237
+ #### Retrieve a database
238
+
239
+ Retrieves a [Database object](https://developers.notion.com/reference-link/database) using the ID specified.
240
+
241
+ ```ruby
242
+ client.database(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')
243
+ ```
244
+
245
+ The response's `data_sources` field lists the data source ids and names that belong to this database, e.g. `response.data_sources.first.id`, for use with the endpoints below.
246
+
247
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-database).
248
+
249
+ ### Data sources
250
+
251
+ > :blue_book: `relation` property **values** (e.g. when setting a `relation` property via `create_page`/`update_page`) must reference a `data_source_id` as of `Notion-Version` `2025-09-03` — `database_id` is no longer accepted when writing. Reading a page back still includes both `database_id` and `data_source_id` on relation values for compatibility. The gem does not validate property payloads (for any property type), so this is a data-shape change on the caller's side, not something enforced here.
252
+
253
+ #### Query a data source
254
+
255
+ Gets a paginated array of [Page](https://developers.notion.com/reference/page) objects contained in the data source, filtered and ordered according to the filter conditions and sort criteria provided in the request. This replaces `database_query` as of `Notion-Version` `2025-09-03`.
256
+
257
+ ```ruby
258
+ database = client.database(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')
259
+ data_source_id = database.data_sources.first.id
260
+
261
+ client.data_source_query(data_source_id: data_source_id) # retrieves the first page
262
+
263
+ client.data_source_query(data_source_id: data_source_id, start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
264
+
265
+ client.data_source_query(data_source_id: data_source_id) do |page|
266
+ # paginate through all pages
267
+ end
268
+
269
+ client.data_source_query(data_source_id: data_source_id, sorts: sorts, filter: filter)
270
+ ```
271
+
272
+ See [Pagination](#pagination) for details about how to iterate through the list.
273
+
274
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/query-a-data-source).
275
+
276
+ #### Create a data source
277
+
278
+ Adds a new data source to an existing database.
279
+
280
+ ```ruby
281
+ client.create_data_source(
282
+ parent: { database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0' },
283
+ title: title,
284
+ properties: properties
285
+ )
286
+ ```
287
+
288
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/create-a-data-source).
289
+
290
+ #### Update a data source
291
+
292
+ Updates an existing data source's title or property schema.
293
+
294
+ ```ruby
295
+ client.update_data_source(data_source_id: data_source_id, title: title)
296
+ ```
297
+
298
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/update-a-data-source).
299
+
300
+ #### Retrieve a data source
301
+
302
+ Retrieves a data source object using the ID specified.
303
+
304
+ ```ruby
305
+ client.data_source(data_source_id: data_source_id)
306
+ ```
307
+
308
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-data-source).
309
+
310
+ ### Pages
311
+
312
+ #### Retrieve a page
313
+
314
+ Retrieves a [Page object](https://developers.notion.com/reference-link/page) using the ID specified.
315
+
316
+ > :blue_book: Responses contains page **properties**, not page content. To fetch page content, use the [retrieve block children](#retrieve-block-children) endpoint.
317
+
318
+ ```ruby
319
+ client.page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
320
+ ```
321
+
322
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-page).
323
+
324
+ #### Create a page
325
+
326
+ Creates a new page in the specified data source (or database) or as a child of an existing page.
327
+
328
+ > :blue_book: As of `Notion-Version` `2025-09-03`, prefer `parent: { data_source_id: ... }` over `parent: { database_id: ... }`; the latter keeps working for databases with a single data source. See [Data sources](#data-sources).
329
+
330
+ If the parent is a data source or database, the [property values](https://developers.notion.com/reference-link/page-property-values) of the new page in the properties parameter must conform to the parent's property schema.
331
+
332
+ If the parent is a page, the only valid property is `title`.
333
+
334
+ The new page may include page content, described as [blocks](https://developers.notion.com/reference-link/block) in the children parameter.
335
+
336
+ The following example creates a new page within the specified database:
337
+
338
+ ```ruby
339
+ properties = {
340
+ 'Name': {
341
+ 'title': [
342
+ {
343
+ 'text': {
344
+ 'content': 'Tuscan Kale'
345
+ }
346
+ }
347
+ ]
348
+ },
349
+ 'Description': {
350
+ 'rich_text': [
351
+ {
352
+ 'text': {
353
+ 'content': 'A dark green leafy vegetable'
354
+ }
355
+ }
356
+ ]
357
+ },
358
+ 'Food group': {
359
+ 'select': {
360
+ 'name': '🥦 Vegetable'
361
+ }
362
+ },
363
+ 'Price': {
364
+ 'number': 2.5
365
+ }
366
+ }
367
+ children = [
368
+ {
369
+ 'object': 'block',
370
+ 'type': 'heading_2',
371
+ 'heading_2': {
372
+ 'rich_text': [{
373
+ 'type': 'text',
374
+ 'text': { 'content': 'Lacinato kale' }
375
+ }]
376
+ }
377
+ },
378
+ {
379
+ 'object': 'block',
380
+ 'type': 'paragraph',
381
+ 'paragraph': {
382
+ 'rich_text': [
383
+ {
384
+ 'type': 'text',
385
+ 'text': {
386
+ 'content': 'Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.',
387
+ 'link': { 'url': 'https://en.wikipedia.org/wiki/Lacinato_kale' }
388
+ }
389
+ }
390
+ ]
391
+ }
392
+ }
393
+ ]
394
+ client.create_page(
395
+ parent: { database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0'},
396
+ properties: properties,
397
+ children: children
398
+ )
399
+ ```
400
+
401
+ This example creates a new page as a child of an existing page.
402
+
403
+ ```ruby
404
+ properties = {
405
+ title: [
406
+ {
407
+ "type": "text",
408
+ "text": {
409
+ "content": "My favorite food",
410
+ "link": null
411
+ }
412
+ }
413
+ ]
414
+ }
415
+ children = [
416
+ {
417
+ 'object': 'block',
418
+ 'type': 'heading_2',
419
+ 'heading_2': {
420
+ 'rich_text': [{
421
+ 'type': 'text',
422
+ 'text': { 'content': 'Lacinato kale' }
423
+ }]
424
+ }
425
+ },
426
+ {
427
+ 'object': 'block',
428
+ 'type': 'paragraph',
429
+ 'paragraph': {
430
+ 'rich_text': [
431
+ {
432
+ 'type': 'text',
433
+ 'text': {
434
+ 'content': 'Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.',
435
+ 'link': { 'url': 'https://en.wikipedia.org/wiki/Lacinato_kale' }
436
+ }
437
+ }
438
+ ]
439
+ }
440
+ }
441
+ ]
442
+ client.create_page(
443
+ parent: { page_id: 'feb1cdfaab6a43cea4ecbc9e8de63ef7'},
444
+ properties: properties,
445
+ children: children
446
+ )
447
+ ```
448
+
449
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-page).
450
+
451
+ #### Update page
452
+
453
+ Updates [page property values](https://developers.notion.com/reference-link/page-property-value) for the specified page. Properties that are not set via the `properties` parameter will remain unchanged.
454
+
455
+ If the parent is a database, the new [property values](https://developers.notion.com/reference-link/page-property-value) in the `properties` parameter must conform to the parent [database](https://developers.notion.com/reference-link/database)'s property schema.
456
+
457
+ ```ruby
458
+ properties = {
459
+ 'In stock': {
460
+ 'checkbox': true
461
+ }
462
+ }
463
+ client.update_page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', properties: properties)
464
+ ```
465
+
466
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-page).
467
+
468
+ #### Retrieve a page property item
469
+
470
+ Retrieves a `property_item` object for a given `page_id` and `property_id`. Depending on the property type, the object returned will either be a value or a [paginated](#pagination) list of property item values. See [Property item objects](https://developers.notion.com/reference/property-item-object) for specifics.
471
+
472
+ To obtain `property_id`'s, use the [Retrieve a database endpoint](#retrieve-a-database).
473
+
474
+ ```ruby
475
+ client.page_property_item(
476
+ page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75',
477
+ property_id: 'aBcD123'
478
+ )
479
+ ```
480
+
481
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-page-property).
482
+
483
+ ### Blocks
484
+
485
+ #### Retrieve a block
486
+
487
+ Retrieves a [Block object](https://developers.notion.com/reference-link/block) using the ID specified.
488
+
489
+ > :blue_book: If a block contains the key `has_children: true`, use the [Retrieve block children](#retrieve-block-children) endpoint to get the list of children
490
+
491
+ ```ruby
492
+ client.block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6')
493
+ ```
494
+
495
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).
496
+
497
+ #### Update a block
498
+
499
+ Updates the content for the specified block_id based on the block type. Supported fields based on the block object type (see [Block object](https://developers.notion.com/reference-link/block#block-type-object) for available fields and the expected input for each field).
500
+
501
+ **Note** The update replaces the entire value for a given field. If a field is omitted (ex: omitting checked when updating a to_do block), the value will not be changed.
502
+
503
+ ```ruby
504
+ to_do = {
505
+ 'rich_text': [{
506
+ 'type': 'text',
507
+ 'text': { 'content': 'Lacinato kale' }
508
+ }],
509
+ 'checked': false
510
+ }
511
+ client.update_block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6', 'to_do' => to_do)
512
+ ```
513
+
514
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).
515
+
516
+ #### Delete a block
517
+
518
+ Sets a [Block object](https://developers.notion.com/reference/block), including page blocks, to archived: true using the ID specified. Note: in the Notion UI application, this moves the block to the "Trash" where it can still be accessed and restored.
519
+
520
+ To restore the block with the API, use the [Update a block](#update-a-block) or [Update page](#update-page) respectively.
521
+
522
+ ```ruby
523
+ client.delete_block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6')
524
+ ```
525
+
526
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/delete-a-block).
527
+
528
+ #### Retrieve block children
529
+
530
+ Returns a paginated array of child [block objects](https://developers.notion.com/reference-link/block) contained in the block using the ID specified. In order to receive a complete representation of a block, you may need to recursively retrieve the block children of child blocks.
531
+
532
+ ```ruby
533
+ client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')
534
+
535
+ client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
536
+
537
+ client.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75') do |page|
538
+ # paginate through all children
539
+ end
540
+ ```
541
+
542
+ See [Pagination](#pagination) for details about how to iterate through the list.
543
+
544
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-block-children).
545
+
546
+ #### Append block children
547
+
548
+ Creates and appends new children blocks to the parent block specified by `block_id`.
549
+
550
+ Returns a paginated list of newly created first level children block objects.
551
+
552
+ ```ruby
553
+ children = [
554
+ {
555
+ "object": 'block',
556
+ "type": 'heading_2',
557
+ 'heading_2': {
558
+ 'rich_text': [{
559
+ 'type': 'text',
560
+ 'text': { 'content': 'A Second-level Heading' }
561
+ }]
562
+ }
563
+ }
564
+ ]
565
+ client.block_append_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', children: children)
566
+ ```
567
+
568
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-block-children).
569
+
570
+ ### Comments
571
+
572
+ #### Retrieve comments from a page or block by id
573
+ ```ruby
574
+ client.retrieve_comments(block_id: '1a2f70ab26154dc7a838536a3f430af4')
575
+ ```
576
+ #### Create a comment on a page
577
+ ```ruby
578
+ options = {
579
+ parent: { page_id: '3e4bc91d36c74de595113b31c6fdb82c' },
580
+ rich_text: [
581
+ {
582
+ text: {
583
+ content: 'Hello world'
584
+ }
585
+ }
586
+ ]
587
+ }
588
+ client.create_comment(options)
589
+ ```
590
+ #### Create a comment on a discussion
591
+ ```ruby
592
+ options = {
593
+ discussion_id: 'ea116af4839c410bb4ac242a18dc4392',
594
+ rich_text: [
595
+ {
596
+ text: {
597
+ content: 'Hello world'
598
+ }
599
+ }
600
+ ]
601
+ }
602
+ client.create_comment(options)
603
+ ```
604
+
605
+ See the full endpoint documention on [Notion Developers](https://developers.notion.com/reference/comment-object).
606
+
607
+ ### Users
608
+
609
+ #### Retrieve your token's bot user
610
+
611
+ Retrieves the bot [User](https://developers.notion.com/reference/user) associated with the API token provided in the authorization header. The bot will have an `owner` field with information about the person who authorized the integration.
612
+
613
+ ```ruby
614
+ client.me
615
+ ```
616
+
617
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-self).
618
+
619
+ #### Retrieve a user
620
+
621
+ Retrieves a [User](https://developers.notion.com/reference/user) using the ID specified.
622
+
623
+ ```ruby
624
+ client.user(user_id: 'd40e767c-d7af-4b18-a86d-55c61f1e39a4')
625
+ ```
626
+
627
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-user).
628
+
629
+ #### List all users
630
+
631
+ Returns a paginated list of [Users](https://developers.notion.com/reference/user) for the workspace.
632
+
633
+ ```ruby
634
+ client.users_list # retrieves the first page
635
+
636
+ client.users_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
637
+
638
+ client.users_list do |page|
639
+ # paginate through all users
640
+ end
641
+ ```
642
+
643
+ See [Pagination](#pagination) for details about how to iterate through the list.
644
+
645
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-users).
646
+
647
+ ### Search
648
+
649
+ Searches all pages and child pages that are shared with the integration. The results may include data sources.
650
+
651
+ > :blue_book: As of `Notion-Version` `2025-09-03`, the `filter` value `'database'` is replaced by `'data_source'`, and matching results are returned as `"object": "data_source"` (one per data source, so a database with multiple data sources yields multiple results) instead of `"object": "database"`. Code that filters search results by `object == 'database'` needs to check for `'data_source'` instead.
652
+
653
+ ```ruby
654
+ client.search # search through every available page and data source
655
+
656
+ client.search(query: 'Specific query') # limits which pages are returned by comparing the query to the page title
657
+
658
+ client.search(filter: { property: 'object', value: 'page' }) # only returns pages
659
+
660
+ client.search(filter: { property: 'object', value: 'data_source' }) # only returns data sources
661
+
662
+ client.search(sort: { direction: 'ascending', timestamp: 'last_edited_time' }) # sorts the results based on the provided criteria.
663
+
664
+ client.search(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')
665
+
666
+ client.search do |page|
667
+ # paginate through all search pages
668
+ end
669
+ ```
670
+
671
+ See [Pagination](#pagination) for details about how to iterate through the list.
672
+
673
+ See the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-search).
674
+
675
+ ## Acknowledgements
676
+
677
+ The code, specs and documentation of this gem are an adaptation of the fantastic [Slack Ruby Client](https://github.com/slack-ruby/slack-ruby-client) gem. Many thanks to its author and maintainer [@dblock](https://github.com/dblock) and [contributors](https://github.com/slack-ruby/slack-ruby-client/graphs/contributors).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'bundler/gem_tasks'
5
+
6
+ Bundler.setup :default, :development
7
+
8
+ require 'rspec/core'
9
+ require 'rspec/core/rake_task'
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |spec|
12
+ spec.pattern = FileList['spec/**/*_spec.rb']
13
+ end
14
+
15
+ require 'rubocop/rake_task'
16
+ RuboCop::RakeTask.new
17
+
18
+ task default: %i[spec rubocop]