Notion API master series 15 - Retrieve a block & Retrieve block children

소찬 (Chan)·2022년 10월 24일
0
post-thumbnail

Reference API URL : Retrieve a block, Retrieve block children

We learned about the page, so let's look into the block.
See 'retrieve a block' that mentioned block_id from parameter. By the way, how to bring block_id? Try 'Retrieve block children', then we can get it.
Bunches of a block is a page,
Bunches of a page is a database.
We can use page_id with block_id. Consider page_id as parent id and call blocks.children.list. Then we can find block_id.

page_id = '1f217cc1-225f-4580-8e22-cd7eb8db3c5e'
blocks = notion.blocks.children.list(block_id=page_id)

This below is part of called information.

{...
 'results': [{'archived': False,
              ...
              'has_children': False,
              'id': '27b0ad2f-5698-4f7c-ab07-00f174042264',
              ...
              },
             {'archived': False,
              ...
              'has_children': False,
              'id': 'fc98ddff-fd10-4705-b22e-e4f259cc2ce4',
              ...
              }],
 'type': 'block'}

Here id of block information from the list of results is block_id.
If we want to bring first block information, get [0]th information, and second block info, get [1]st information.

target_block_id = blocks['results'][0]['id']

To retrieve block information code is as below.

notion.blocks.retrieve(block_id=target_block_id)
pprint(target_block)

Next, is an available option called blocks.children.list(Retrieve block children).

  • page_size (int32)
    For paginated properties. The max number of property item objects on a page. The default size is 100
    We can set property item bunch sizes as only one or a maximum of 100.

  • start_cursor (string)
    For paginated properties.
    If the return value is has_more : True, and also return value gives next_cursor value together.

 'has_more': True,
 'next_cursor': 'fc98ddff-fd10-4705-b22e-e4f259cc2ce4',
 'object': 'list',
 'results': [{'archived': False, ...

Input next_cursor value into start_cursor and call retrieve. Then we can bring more results.

profile
QA Specialist

0개의 댓글