It's not the end. Chan is back again.
For this time, I serialize for the Sync Block function.
If you mouse over a specific area, then you may see dimmed red focused block. This block
is Sync Block. Then let's find out how these blocks form.
parameter
filter={"property": "object", "value": "page"}
from the search
method and search
the page
with a sync block. And put page_id
into the variable. (refer to Analysis 08, 09 series)blocks.children.list
with page_id
value and look into the block information which has a sync block. (refer to Analysis 15 series)See an example here.
{'archived': False,
'created_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
'created_time': '2022-08-03T02:48:00.000Z',
'has_children': True,
'id': '741f841e-1fa3-412b-929c-00000000000',
'last_edited_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
'last_edited_time': '2022-08-03T02:48:00.000Z',
'object': 'block',
'parent': {'page_id': '65f095e3-1027-4589-a504-3d3359b6c20f',
'type': 'page_id'},
'synced_block': {'synced_from': None},
'type': 'synced_block'}
'type'
is 'synced_block'
. For this time, how can we retrieve
block
data?
Sharp-shaped people realize that 'has_children'
is True. This block_id
is as page_id
and call blocks.children.list
then we can see sync block details.
Wait... By the way, some block
shows like as below.
{'archived': False,
'created_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
'created_time': '2022-08-03T02:49:00.000Z',
'has_children': True,
'id': '2beb9496-1372-4e4d-a7c3-b7c497ab7b9b',
'last_edited_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
'last_edited_time': '2022-08-03T02:49:00.000Z',
'object': 'block',
'parent': {'page_id': 'ef086465-015e-4be9-8911-83000865637e',
'type': 'page_id'},
'synced_block': {'synced_from': {'block_id': '741f841e-1fa3-412b-929c-00000000000',
'type': 'block_id'}},
'type': 'synced_block'}
Like above block
, 'synced_block'
contains 'block_id'
information. What are the differences? If 'synced_from'
in 'synced_block'
is None
, that means I'm the original. If it contains 'block_id'
, I'm a copied sync block, and the original exists separately. The original id is 'block_id'
.
Look at the details, then you realize 'block_id'
from 'synced_from'
and 'id'
of the last block are the same.
'id': '741f841e-1fa3-412b-929c-00000000000'
'block_id': '741f841e-1fa3-412b-929c-00000000000'
Then now put id into the sync_block_id
variable.
sync_block_id = '741f841e-1fa3-412b-929c-00000000000'
Now call blocks.children.list
.
(If the object name is notion
)
sync_blocks = notion.blocks.children.list(block_id=sync_block_id)
pprint(sync_blocks)
We can see bunches of blocks in a sync block.
{'block': {},
'has_more': False,
'next_cursor': None,
'object': 'list',
'results': [{'archived': False,
'created_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
....
If has_more
is True
, put the parameter
value 'next_cursor'
into 'start_cursor'
and call the method. Bunches amount also set page_size
for calling at once.
next_cursor = sync_blocks['next_cursor']
notion.blocks.children.list(block_id=sync_block_id, start_cursor=next_cursor, page_size=20)
Series 24 is the end. I will finish up the series.
Now I am trying to finish the series. I feel lighthearted. Enjoy Notion life, and I'm the author of the Notion API master series, Chan Baek.
Thank you so much for loving this series.