{"id":8877574,"url":"https://github.com/phacks/notion-ruby-client","last_synced_at":"2025-10-04T21:50:41.023Z","repository":{"id":42052572,"uuid":"334246963","full_name":"phacks/notion-ruby-client","owner":"phacks","description":"A Ruby client for the Notion API","archived":false,"fork":false,"pushed_at":"2024-08-01T23:24:52.000Z","size":491,"stargazers_count":126,"open_issues_count":6,"forks_count":26,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-12T05:09:45.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phacks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-29T19:45:44.000Z","updated_at":"2025-09-12T01:44:55.000Z","dependencies_parsed_at":"2023-02-12T07:45:15.591Z","dependency_job_id":"a37a4b09-f6ff-4675-899a-ef90f10f853c","html_url":"https://github.com/phacks/notion-ruby-client","commit_stats":{"total_commits":111,"total_committers":14,"mean_commits":7.928571428571429,"dds":0.3063063063063063,"last_synced_commit":"bef2c28669640e51e629ba3ba40c510775775011"},"previous_names":["phacks/notion-ruby-client","orbit-love/notion-ruby-client"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/phacks/notion-ruby-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phacks%2Fnotion-ruby-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phacks%2Fnotion-ruby-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phacks%2Fnotion-ruby-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phacks%2Fnotion-ruby-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phacks","download_url":"https://codeload.github.com/phacks/notion-ruby-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phacks%2Fnotion-ruby-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278380463,"owners_count":25977216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-05-01T07:04:14.389Z","updated_at":"2025-10-04T21:50:40.960Z","avatar_url":"https://github.com/phacks.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Notion Ruby Client\n\n[![Gem Version](https://badge.fury.io/rb/notion-ruby-client.svg)](http://badge.fury.io/rb/notion-ruby-client)\n[![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)\n\nA Ruby client for the Notion API.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Create a New Bot Integration](#create-a-new-bot-integration)\n  - [Declare the API token](#declare-the-api-token)\n  - [API Client](#api-client)\n    - [Instantiating a new Notion API client](#instantiating-a-new-notion-api-client)\n    - [Pagination](#pagination)\n- [Endpoints](#endpoints)\n  - [Databases](#databases)\n    - [Query a database](#query-a-database)\n    - [Create a Database](#create-a-database)\n    - [Update a Database](#update-a-database)\n    - [Retrieve a database](#retrieve-a-database)\n  - [Pages](#pages)\n    - [Retrieve a page](#retrieve-a-page)\n    - [Create a page](#create-a-page)\n    - [Update page](#update-page)\n    - [Retrieve a page property item](#retrieve-a-page-property-item)\n  - [Blocks](#blocks)\n    - [Retrieve a block](#retrieve-a-block)\n    - [Update a block](#update-a-block)\n    - [Delete a block](#delete-a-block)\n    - [Retrieve block children](#retrieve-block-children)\n    - [Append block children](#append-block-children)\n  - [Comments](#comments)\n    - [Retrieve comments](#retrieve-comments-from-a-page-or-block-by-id)\n    - [Create a comment on a page](#create-a-comment-on-a-page)\n    - [Create a comment on a discussion](#create-a-comment-on-a-discussion)\n  - [Users](#users)\n    - [Retrieve your token's bot user](#retrieve-your-tokens-bot-user)\n    - [Retrieve a user](#retrieve-a-user)\n    - [List all users](#list-all-users)\n  - [Search](#search)\n- [Acknowledgements](#acknowledgements)\n\n## Installation\n\nAdd to Gemfile.\n\n```\ngem 'notion-ruby-client'\n```\n\nRun `bundle install`.\n\n## Usage\n\n### Create a New Integration\n\n\u003e :blue_book: **Before you start**\n\u003e\n\u003e 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).\n\nTo create a new integration, follow the steps 1 \u0026 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”).\n\n\u003e :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.**\n\n### Declare the API token\n\n```ruby\nNotion.configure do |config|\n  config.token = ENV['NOTION_API_TOKEN']\nend\n```\n\nFor Rails projects, the snippet above would go to `config/application.rb`.\n\n### API Client\n\n#### Instantiating a new Notion API client\n\n```ruby\nclient = Notion::Client.new\n```\n\nYou can specify the token or logger on a per-client basis:\n\n```ruby\nclient = Notion::Client.new(token: '\u003csecret Notion API token\u003e')\n```\n\n#### Pagination\n\nThe 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.\n\n```ruby\nall_users = []\nclient.users_list(page_size: 25) do |page|\n  all_users.concat(page.results)\nend\nall_users # All users, retrieved 25 at a time\n```\n\nWhen 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`.\n\nYou can also proactively avoid rate limiting by adding a pause between every paginated request with the `sleep_interval` parameter, which is given in seconds.\n\n```ruby\nall_users = []\nclient.users_list(sleep_interval: 5, max_retries: 20) do |page|\n  # pauses for 5 seconds between each request\n  # gives up after 20 consecutive rate-limited responses\n  all_users.concat(page.results)\nend\nall_users\n```\n\n## Endpoints\n\n### Databases\n\n#### Query a database\n\nGets 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.\n\n```ruby\nclient.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')  # retrieves the first page\n\nclient.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')\n\nclient.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0') do |page|\n  # paginate through all pages\nend\n\n# Filter and sort the database\nsorts = [\n  {\n    'timestamp': 'created_time',\n    'direction': 'ascending'\n  }\n]\nfilter = {\n  'or': [\n    {\n      'property': 'In stock',\n      'checkbox': {\n        'equals': true\n      }\n    },\n    {\n      'property': 'Cost of next trip',\n      'number': {\n        'greater_than_or_equal_to': 2\n      }\n    }\n  ]\n}\nclient.database_query(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0', sorts: sorts, filter: filter)\n```\n\nSee [Pagination](#pagination) for details about how to iterate through the list.\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-database-query).\n\n#### Create a Database\n\nCreates a database as a subpage in the specified parent page, with the specified properties schema.\n\n```ruby\ntitle = [\n  {\n    'type': 'text',\n    'text': {\n      'content': 'Grocery List',\n      'link': nil\n    }\n  }\n]\nproperties = {\n  'Name': {\n    'title': {}\n  },\n  'Description': {\n    'rich_text': {}\n  },\n  'In stock': {\n    'checkbox': {}\n  },\n  'Food group': {\n    'select': {\n      'options': [\n        {\n          'name': '🥦Vegetable',\n          'color': 'green'\n        },\n        {\n          'name': '🍎Fruit',\n          'color': 'red'\n        },\n        {\n          'name': '💪Protein',\n          'color': 'yellow'\n        }\n      ]\n    }\n  }\n}\nclient.create_database(\n  parent: { page_id: '98ad959b-2b6a-4774-80ee-00246fb0ea9b' },\n  title: title,\n  properties: properties\n)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/create-a-database).\n\n#### Update a Database\n\nUpdates an existing database as specified by the parameters.\n\n```ruby\ntitle = [\n  {\n    'text': {\n      'content': 'Orbit 💜 Notion'\n    }\n  }\n]\nclient.update_database(database_id: 'dd428e9dd3fe4171870da7a1902c748b', title: title)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/update-a-database).\n\n#### Retrieve a database\n\nRetrieves a [Database object](https://developers.notion.com/reference-link/database) using the ID specified.\n\n```ruby\nclient.database(database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0')\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-database).\n\n### Pages\n\n#### Retrieve a page\n\nRetrieves a [Page object](https://developers.notion.com/reference-link/page) using the ID specified.\n\n\u003e :blue_book: Responses contains page **properties**, not page content. To fetch page content, use the [retrieve block children](#retrieve-block-children) endpoint.\n\n```ruby\nclient.page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-page).\n\n#### Create a page\n\nCreates a new page in the specified database or as a child of an existing page.\n\nIf the parent is a 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 [database](https://developers.notion.com/reference-link/database)'s property schema.\n\nIf the parent is a page, the only valid property is `title`.\n\nThe new page may include page content, described as [blocks](https://developers.notion.com/reference-link/block) in the children parameter.\n\nThe following example creates a new page within the specified database:\n\n```ruby\nproperties = {\n  'Name': {\n    'title': [\n      {\n        'text': {\n          'content': 'Tuscan Kale'\n        }\n      }\n    ]\n  },\n  'Description': {\n    'rich_text': [\n      {\n        'text': {\n          'content': 'A dark green leafy vegetable'\n        }\n      }\n    ]\n  },\n  'Food group': {\n    'select': {\n      'name': '🥦 Vegetable'\n    }\n  },\n  'Price': {\n    'number': 2.5\n  }\n}\nchildren = [\n  {\n    'object': 'block',\n    'type': 'heading_2',\n    'heading_2': {\n      'rich_text': [{\n        'type': 'text',\n        'text': { 'content': 'Lacinato kale' }\n      }]\n    }\n  },\n  {\n    'object': 'block',\n    'type': 'paragraph',\n    'paragraph': {\n      'rich_text': [\n        {\n          'type': 'text',\n          'text': {\n            '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.',\n            'link': { 'url': 'https://en.wikipedia.org/wiki/Lacinato_kale' }\n          }\n        }\n      ]\n    }\n  }\n]\nclient.create_page(\n   parent: { database_id: 'e383bcee-e0d8-4564-9c63-900d307abdb0'},\n   properties: properties,\n   children: children\n)\n```\n\nThis example creates a new page as a child of an existing page.\n\n```ruby\nproperties = {\n  title: [\n    {\n      \"type\": \"text\",\n      \"text\": {\n        \"content\": \"My favorite food\",\n        \"link\": null\n      }\n    }\n  ]\n}\nchildren = [\n  {\n    'object': 'block',\n    'type': 'heading_2',\n    'heading_2': {\n      'rich_text': [{\n        'type': 'text',\n        'text': { 'content': 'Lacinato kale' }\n      }]\n    }\n  },\n  {\n    'object': 'block',\n    'type': 'paragraph',\n    'paragraph': {\n      'rich_text': [\n        {\n          'type': 'text',\n          'text': {\n            '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.',\n            'link': { 'url': 'https://en.wikipedia.org/wiki/Lacinato_kale' }\n          }\n        }\n      ]\n    }\n  }\n]\nclient.create_page(\n   parent: { page_id: 'feb1cdfaab6a43cea4ecbc9e8de63ef7'},\n   properties: properties,\n   children: children\n)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-page).\n\n#### Update page\n\nUpdates [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.\n\nIf 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.\n\n```ruby\nproperties = {\n  'In stock': {\n    'checkbox': true\n  }\n}\nclient.update_page(page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', properties: properties)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-page).\n\n#### Retrieve a page property item\n\nRetrieves 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.\n\nTo obtain `property_id`'s, use the [Retrieve a database endpoint](#retrieve-a-database).\n\n```ruby\nclient.page_property_item(\n  page_id: 'b55c9c91-384d-452b-81db-d1ef79372b75',\n  property_id: 'aBcD123'\n)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-page-property).\n\n### Blocks\n\n#### Retrieve a block\n\nRetrieves a [Block object](https://developers.notion.com/reference-link/block) using the ID specified.\n\n\u003e :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\n\n```ruby\nclient.block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6')\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).\n\n#### Update a block\n\nUpdates 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).\n\n**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.\n\n```ruby\nto_do = {\n  'rich_text': [{\n    'type': 'text',\n    'text': { 'content': 'Lacinato kale' }\n    }],\n  'checked': false\n}\nclient.update_block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6', 'to_do' =\u003e to_do)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/retrieve-a-block).\n\n#### Delete a block\n\nSets 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.\n\nTo restore the block with the API, use the [Update a block](#update-a-block) or [Update page](#update-page) respectively.\n\n```ruby\nclient.delete_block(block_id: '9bc30ad4-9373-46a5-84ab-0a7845ee52e6')\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/delete-a-block).\n\n#### Retrieve block children\n\nReturns 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.\n\n```ruby\nclient.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75')\n\nclient.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')\n\nclient.block_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75') do |page|\n  # paginate through all children\nend\n```\n\nSee [Pagination](#pagination) for details about how to iterate through the list.\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-block-children).\n\n#### Append block children\n\nCreates and appends new children blocks to the parent block specified by `block_id`.\n\nReturns a paginated list of newly created first level children block objects.\n\n```ruby\nchildren = [\n  {\n    \"object\": 'block',\n    \"type\": 'heading_2',\n    'heading_2': {\n      'rich_text': [{\n        'type': 'text',\n        'text': { 'content': 'A Second-level Heading' }\n      }]\n    }\n  }\n]\nclient.block_append_children(block_id: 'b55c9c91-384d-452b-81db-d1ef79372b75', children: children)\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/patch-block-children).\n\n### Comments\n\n#### Retrieve comments from a page or block by id\n```ruby\nclient.retrieve_comments(block_id: '1a2f70ab26154dc7a838536a3f430af4')\n```\n#### Create a comment on a page\n```ruby\noptions = {\n  parent: { page_id: '3e4bc91d36c74de595113b31c6fdb82c' },\n  rich_text: [\n    {\n      text: {\n        content: 'Hello world'\n      }\n    }\n  ]\n}\nclient.create_comment(options)\n```\n#### Create a comment on a discussion\n```ruby\noptions = {\n  discussion_id: 'ea116af4839c410bb4ac242a18dc4392',\n  rich_text: [\n    {\n      text: {\n        content: 'Hello world'\n      }\n    }\n  ]\n}\nclient.create_comment(options)\n```\n\nSee the full endpoint documention on [Notion Developers](https://developers.notion.com/reference/comment-object).\n\n### Users\n\n#### Retrieve your token's bot user\n\nRetrieves 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.\n\n```ruby\nclient.me\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-self).\n\n#### Retrieve a user\n\nRetrieves a [User](https://developers.notion.com/reference/user) using the ID specified.\n\n```ruby\nclient.user(user_id: 'd40e767c-d7af-4b18-a86d-55c61f1e39a4')\n```\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-user).\n\n#### List all users\n\nReturns a paginated list of [Users](https://developers.notion.com/reference/user) for the workspace.\n\n```ruby\nclient.users_list # retrieves the first page\n\nclient.users_list(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')\n\nclient.users_list do |page|\n  # paginate through all users\nend\n```\n\nSee [Pagination](#pagination) for details about how to iterate through the list.\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/get-users).\n\n### Search\n\nSearches all pages and child pages that are shared with the integration. The results may include databases.\n\n```ruby\nclient.search # search through every available page and database\n\nclient.search(query: 'Specific query') # limits which pages are returned by comparing the query to the page title\n\nclient.search(filter: { property: 'object', value: 'page' }) # only returns pages\n\nclient.search(sort: { direction: 'ascending', timestamp: 'last_edited_time' }) # sorts the results based on the provided criteria.\n\nclient.search(start_cursor: 'fe2cc560-036c-44cd-90e8-294d5a74cebc')\n\nclient.search do |page|\n  # paginate through all search pages\nend\n```\n\nSee [Pagination](#pagination) for details about how to iterate through the list.\n\nSee the full endpoint documentation on [Notion Developers](https://developers.notion.com/reference/post-search).\n\n## Acknowledgements\n\nThe 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).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphacks%2Fnotion-ruby-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphacks%2Fnotion-ruby-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphacks%2Fnotion-ruby-client/lists"}