2. Notion API Documentation

This module contains the Notion class, which is a subclass of the API class. It is used to interact with the Notion API. The Notion API is documented here: https://developers.notion.com/reference/intro

class notion.Notion(test=False)

Bases : API

The reference is your key to a comprehensive understanding of the Notion API.

Integrations use the API to access Notion’s pages, databases, and users. Integrations can connect services to Notion and build interactive experiences for users within Notion. Using the navigation on the left, you’ll find details for objects and endpoints used in the API.

https://developers.notion.com/reference/intro

_abc_impl = <_abc_data object>
append_block_children(block_id, children, after=None)

Append children to a block.

Paramètres:
  • block_id – The ID of the block.

  • children – The children to append.

Must be a list of block objects. :param after: (optional) The child block to add the new children after.

Default is None, which appends the children at the end of the block.

Renvoie:

The response contains the block’s data.

Type renvoyé:

api.RequestResponse

Lève:

TypeError – If the « children » parameter is not a list of block objects.

create_database(parent, properties, title=None)

Creates a database as a subpage in the specified parent page, with the specified properties” schema. Currently, the parent of a new database must be a Notion page.

Paramètres:
  • parent – The ID of the parent page.

  • properties – The properties of the database.

  • title – (optional) The title of the database.

Renvoie:

The response contains the database’s data.

Type renvoyé:

api.RequestResponse

delete_block(block_id)

Delete a block from Notion API.

Paramètres:

block_id – The ID of the block.

Renvoie:

The response contains the block’s data.

Type renvoyé:

api.RequestResponse

get_block(block_id)

Retrieve a block from Notion API.

Paramètres:

block_id – The ID of the block.

Renvoie:

The response contains the block’s data.

Type renvoyé:

api.RequestResponse

get_block_children(block_id)

Retrieve a block’s children from Notion API.

Paramètres:

block_id – The ID of the block.

Renvoie:

The response contains the block’s children.

Type renvoyé:

api.RequestResponse

get_database(id)

Retrieves a database object — information that describes the structure and columns of a database — for a provided database ID. The response adheres to any limits to an integration’s capabilities.

To fetch database rows rather than columns, use the « Query a database endpoint. »

Paramètres:

id – The ID of the database.

Renvoie:

A RequestResponse object containing the status code and data of the API request.

get_databases(params)

Retrieves information about a Notion database.

Paramètres:

params – The ID of the database.

Renvoie:

A RequestResponse object containing the status code and data of the API request.

get_page(params)

Retrieve pages from Notion API.

Paramètres:

params – The parameters used to retrieve the pages.

Renvoie:

The response contains the pages” data.

get_page_property(page_id, property_id)

Retrieve a page’s property from Notion API.

Paramètres:
  • page_id – The ID of the page.

  • property_id – The id of the property.

Renvoie:

The response contains the page’s property.

get_user(id=None)

Retrieves a user object using the ID specified in the request URL if id is specified, or retrieves all users that the integration has access to if id is not specified.

Paramètres:

id – The ID of the user.

Renvoie:

A RequestResponse object containing the status code and data of the API request.

oauth_header()

Generate the OAuth header for API requests.

Renvoie:

The OAuth header.

Type renvoyé:

dict

patch_database(id, title=None, description=None, properties=None)

Updates the database object — the title, description, or properties — of a specified database.

Returns the updated database object.

Database properties represent the columns (or schema) of a database. To update the properties of a database, use the properties body param with this endpoint. Learn more about database properties in the database properties and Update database properties docs.

To update a relation database property, share the related database with the integration. Learn more about relations on the database properties page.

For an overview of how to use the REST API with databases, refer to the Working with databases guide.

Paramètres:
  • id – The ID of the database.

  • title – (optional) The title of the database.

  • description – (optional) The description of the database.

  • properties – (optional) The properties of the database.

Renvoie:

A RequestResponse object containing the status code and data of the API request.

patch_page_property(page_id, property=None, archived=False)

Update a page’s property from Notion API.

Paramètres:
  • archived – Boolean value indicating whether the page should be archived or not.

  • page_id – The ID of the page.

  • property – The property to update.

Renvoie:

The response contains the page’s data.

Type renvoyé:

api.RequestResponse

post_page(parent_id, properties, children=None, icon=None, cover=None)

Create a page in Notion.

Paramètres:
  • parent_id – The ID of the parent page.

  • properties – The properties of the page.

  • children – (optional) The children of the page.

  • icon – (optional) The icon of the page.

  • cover – (optional) The cover of the page.

Renvoie:

The response contains the page’s data.

Type renvoyé:

api.RequestResponse

query_database(id, filter=None, sorts=None, start_cursor=None, page_size=None)

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request. The response may contain fewer than page_size of results. If the response includes a next_cursor value, refer to the pagination reference for details about how to use a cursor to iterate through the list.

Filters are similar to the filters provided in the Notion UI, where the set of filters and filter groups chained by « And » in the UI is equivalent to having each filter in the array of the compound « and » filter. The same set of filters chained by « Or » in the UI would be represented as filters in the array of the « or » compound filter. Filters operate on database properties and can be combined. If no filter is provided, all the pages in the database will be returned with pagination.

Paramètres:
  • id – The ID of the database.

  • filter – (optional) The filter of the database.

  • sorts – (optional) The sorts of the database.

  • start_cursor – (optional) The start cursor of the database.

  • page_size – (optional) The page size of the database.

Renvoie:

The response contains the database’s data.

Type renvoyé:

api.RequestResponse

search(query, sort=None, filter=None, start_cursor=None, page_size=None)

Searches all pages and child pages that are shared with the integration. The response may contain fewer than page_size of results. If the response includes a next_cursor value, refer to the pagination reference for details about how to use a cursor to iterate through the list.

Paramètres:
  • query – The query of the search.

  • sort – (optional) The sort of the search.

  • filter – (optional) The filter of the search.

  • start_cursor – (optional) The start cursor of the search.

  • page_size – (optional) The page size of the search.

Renvoie:

A RequestResponse object containing the status code and data of the API request.

update_block(block_id, data, archived=False)

Update a block from Notion API.

Paramètres:
  • archived – Boolean value indicating whether the block should be archived or not.

  • block_id – The ID of the block to update.

  • data – The data to update the block with.

Renvoie:

The response contains the block’s data.

Type renvoyé:

api.RequestResponse