Notion API master series 06 - Change the content (Last)

소찬 (Chan)·2022년 8월 15일
0
post-thumbnail

Below the value is the prepared value for an update.
Let's try to update with the below value.

{'rich_text': [{'annotations': {'bold': False,
                                'code': False,
                                'color': 'default',
                                'italic': False,
                                'strikethrough': False,
                                'underline': False},
                'href': None,
                'plain_text': '크러스트가 취향저격',
                'text': {'content': '크러스트가 취향저격', 'link': None},
                'type': 'text'}]}

https://developers.notion.com/reference/update-a-block
Open the API link, and we can guess that blockid is the id for updating the block. However, what does {type}_object mean from BODY PARAMS?
To know this part, we need to read the composition of block_id.

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

{'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',
 'last_edited_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
                    'object': 'user'},
 'last_edited_time': '2022-04-02T12:00:00.000Z',
 'object': 'block',
 'paragraph': {'color': 'default',
               'rich_text': [{'annotations': {'bold': False,
                                              'code': False,
                                              'color': 'default',
                                              'italic': False,
                                              'strikethrough': False,
                                              'underline': False},
                              'href': None,
                              'plain_text': '페퍼로니가 취향저격',
                              'text': {'content': '페퍼로니가 취향저격', 'link': None},
                              'type': 'text'}]},
 'parent': {'page_id': '1f217cc1-225f-4580-8e22-cd7eb8db3c5e',
            'type': 'page_id'},
 'type': 'paragraph'}

Check the key from the above 'rich_text'. What is the key name? Its name is 'paragraph'.
This 'paragraph' is one of {type}. {type}s are various classifications, so it is hard to remember everything—every time you need to find a block document and check the classifications.
https://developers.notion.com/reference/block

Then we learned that {type} is 'paragraph', so launch the code for updating.
Like last time, put target_block_id value into block_id parameter and put the dictionary value contains rich_text into {type}, {type} is 'paragraph' so we can give a parameter like paragraph=rich_text.

notion.blocks.update(block_id=target_block_id, paragraph=rich_text)


Can you see its changes? Then it's a success.

profile
QA Specialist

0개의 댓글