Reference API URL : Delete a block
We could predict that we can call 'Delete a block' with knowing block_id
. For deleting specific block_id
, let's call blocks.children.list
.
blocks = notion.blocks.children.list(block_id=page_id)
pprint(blocks)
Let's find out the result value.
{'block': {},
'has_more': False,
'next_cursor': None,
'object': 'list',
'results': [{'archived': False,
'created_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
'object': 'user'},
'created_time': '2022-04-02T11:59:00.000Z',
'has_children': False,
'id': '27b0ad2f-5698-4f7c-ab07-00f174042264',
...
id
value of 'results'
[0]
th value is the id
of the first block
. [1]
st, value is the second block
. We try to delete the first block
. So put block_id
into a variable. And then we call delete
.
target_block_id = blocks['results'][0]['id']
notion.blocks.delete(block_id=target_block_id)
We can check that API deleted the block. Referring to the document's early part, you can check archived: True
, which means the status in the waste bin. If we call delete
any block but delete
, this status doesn't work. Restore first, and then we can delete
a block.
For restore, call pages.update(page_id=target_page_id, archieve=False)
and change to archive: False
or try to restore manually from notion waste bin and call blocks.delete
then you can delete
a block
.