Reference API URL : Search
query
에 대해 알아보았으니, 다음 parameter
값을 알아보도록 합시다.
last_edited_time
.last_edited_time
옵션만 지원한다는 의미입니다. Notion API 는 계속 업그레이드가 될텐데 아직은 이 옵션만 지원하니 이 옵션 애용해달라, To be continue... 느낌이랄까ascending
and descending
.last_edited_time
.그럼 위 sort 옵션을 코드로 어떻게 작성하면 될까요?
db_or_pages = notion.search(sort={"direction": "ascending", "timestamp": "last_edited_time"})
위와 같이 객체(object)는 dictionary {} 형태로 묶어주시면 됩니다.
database
혹은 page
만 가능합니다.page
or database
. Limitation: Currently the only filter allowed is object
which will filter by type of object (either page
or database
)object
. Limitation: Currently the only filter allowed is object
which will filter by type of object (either page
or database
)위 내용에 맞게 코드를 작성한다면, filter로 가능한 option은 하기 둘중 하나입니다.
notion.search(filter={"property": "object", "value": "page"}
notion.search(filter={"property": "object", "value": "database"}
start_cursor (string)
If supplied, this endpoint will return a page of results starting after the cursor provided. If not supplied, this endpoint will return the first page of results.
search
명령어로 최대 조회해올 수 있는 건이 총 100건입니다. 100건이 초과되는 경우, 응답값에 "has_more" : True
와 "next_cursor": "{고유 id}"
를 보냅니다. next_cursor 를 참조해서 start_cursor를 입력시키면, 101번째부터 그 이후의 결과를 search 해오실 수 있습니다.
page_size (int32)
The number of items from the full list desired in the response. Maximum: 100
한번에 몇 건을 조회에 올지 정하실 수 있습니다. 입력을 따로 안할시에는 최대 100건을 조회해 옵니다.
마무리할 겸 전부 옵션을 넣어 search
를 호출하는 코드를 알아보겠습니다.
next_cursor = 'ff244636-d084-4cfb-93c3-55e6b82f53a0'
cs_block = notion.search(query="고객센터",
sort={"direction": "descending", "timestamp": "last_edited_time"},
filter={"property": "object","value": "page"},
start_cursor=next_cursor,
page_size=10)
위의 코드가 길어보인다면, 가독성 향상을 위해, 변수로 깔쌈(요즘말 드립 욕심 심함)하게 정리해서 호출하셔도 좋습니다.
next_cursor = 'ff244636-d084-4cfb-93c3-55e6b82f53a0'
query_word = '고객센터'
sort_option = {"direction": "descending", "timestamp": "last_edited_time"}
filter_option = {"property": "object","value": "page"}
page_size_default = 10
cs_block = notion.search(query=query_word, sort=sort_option, filter=filter_option,
start_cursor=next_cursor, page_size=page_size_default)