Notion API master series 13 - Analysis - Update page

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

Reference API URL : Update page

We already tried to create a page, so the Update page is it to do easy. But I'm a kind guy, so explain carefully about the Update page.

First, the obstacle is properties before updating because properties are the most sensitive part. So I want to suggest how to read original properties first and modify the properties. And do an update.
Below is an example with executed code, page = notion.pages.retrieve(page_id=target_page_id)

...
 'properties': {'상태': {'id': '%3EQQn',
                       'select': {'color': 'brown',
                                  'id': '588ecfe9-05b0-40c2-aa32-3f26ee0b5281',
                                  'name': '★★★★'},
                       'type': 'select'},
                '이름': {'id': 'title',
                       'title': [{'annotations': {'bold': False,
                                                  'code': False,
                                                  'color': 'default',
                                                  'italic': False,
                                                  'strikethrough': False,
                                                  'underline': False},
                                  'href': None,
                                  'plain_text': '네오피자',
                                  'text': {'content': '네오피자', 'link': None},
                                  'type': 'text'}],
                       'type': 'title'}}

For this, input properties variable.

properties_new = page['properties']

Get rid of unique id from properties_new.

del properties_new['상태']['id']
del properties_new['상태']['select']['id']

And if I want to update only '상태'(status), then we can remove the '이름'(name) property.

del properties_new['이름']

Now we change the stars. We will change five stars.

properties_new['상태']['select']['name'] = '★★★★★'

Note that the property contains color information. We must put the color value as the same color.
For example, the 'green' color set with the five stars option. By the way, if we put five stars with the 'orange' color, then API will return an error.

properties_new['상태']['select']['name'] = '★★★★★'
properties_new['상태']['select']['color'] = 'green'

Now let's try to update.

notion.pages.update(page_id=target_page_id, properties=properties_new)

Then I wonder if the properties set undefined values and update, how does it work? For instance.

properties_new['상태']['select']['name'] = '★★★★★★'
properties_new['상태']['select']['color'] = 'orange'

Six stars option is not in existing cases but is set like above and try to update, and then API will create six stars with the 'orange' color option. Like this.

Let's find out the rest parameter values.

  • archived (boolean)
    Set to true to archive (delete) a page. Set to false to un-archive (restore) a page.
    We can delete a page, but after deleting it, it goes to the trash, not deleted permanently. Give the value archive to True then the page will go to the trash. The other way, change the value to False, then API will restore that page. Trash store deleted pages for 30 days.

  • icon (json)
    Page icon for the new page.
    The icon means Emoji Icon before the page name.

icon_value = {'emoji': '🍕', 'type': 'emoji'}
notion.pages.create(parent=parent_object, properties=properties_new, icon=icon_value)
  • cover (json)
    Page cover for the new page
    Example for adding cover
url = 'https://images.unsplash.com/photo-1566843972142-a7fcb70de55a?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjYzOTIxfQ'
cover_value = {'external': {'url': url},'type': 'external'}
notion.pages.create(parent=parent_object, properties=properties_new, cover=cover_value)
profile
QA Specialist

0개의 댓글