| name | notion-api-5-block-operations |
| description | Sub-skill of notion-api: 5. Block Operations. |
| version | 1.0.0 |
| category | business |
| type | reference |
| scripts_exempt | true |
5. Block Operations
5. Block Operations
Block Types:
{
"type": "paragraph",
"paragraph": {
"rich_text": [{"type": "text", "text": {"content": "Text content"}}]
}
}
{
"type": "heading_1",
"heading_1": {
"rich_text": [{"type": "text", "text": {"content": "Heading 1"}}]
}
}
{
"type": "bulleted_list_item",
"bulleted_list_item": {
"rich_text": [{"type": "text", "text": {"content": "List item"}}]
}
}
{
"type": "numbered_list_item",
"numbered_list_item": {
"rich_text": [{"type": "text", "text": {"content": "Item 1"}}]
}
}
{
"type": "to_do",
"to_do": {
"rich_text": [{"type": "text", "text": {"content": "Task"}}],
"checked": False
}
}
{
"type": "toggle",
"toggle": {
"rich_text": [{"type": "text", "text": {"content": "Toggle header"}}],
"children": []
}
}
{
"type": "code",
"code": {
"rich_text": [{"type": "text", "text": {"content": "print('hello')"}}],
"language": "python"
}
}
{
"type": "quote",
"quote": {
"rich_text": [{"type": "text", "text": {"content": "Quote text"}}]
}
}
{
"type": "callout",
"callout": {
"rich_text": [{"type": "text", "text": {"content": "Important note"}}],
"icon": {"emoji": "💡"}
}
}
{
"type": "divider",
"divider": {}
}
{
"type": "table_of_contents",
"table_of_contents": {}
}
Python - Block Operations:
blocks = notion.blocks.children.list(block_id="page-id")
for block in blocks["results"]:
print(f"Block type: {block['type']}")
notion.blocks.children.append(
block_id="page-id",
children=[
{
"object": "block",
"type": "heading_2",
"heading_2": {
"rich_text": [{"type": "text", "text": {"content": "New Section"}}]
}
},
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{"type": "text", "text": {"content": "Some "}},
{"type": "text", "text": {"content": "bold"}, "annotations": {"bold": True}},
{"type": "text", "text": {"content": " text."}}
]
}
},
{
"object": ,
: ,
: {
: [{: , : {: }}]
}
},
{
: ,
: ,
: {
: [{: , : {: }}]
}
}
]
)
notion.blocks.update(
block_id=,
paragraph={
: [{: , : {: }}]
}
)
notion.blocks.delete(block_id=)
():
all_blocks = []
has_more =
start_cursor =
has_more:
response = notion.blocks.children.(
block_id=block_id,
start_cursor=start_cursor,
page_size=
)
block response[]:
all_blocks.append(block)
block.get():
children = get_all_blocks(block[])
all_blocks.extend(children)
has_more = response[]
start_cursor = response.get()
all_blocks
all_blocks = get_all_blocks()
()