Reference API URL : Search
We learned about the query
, so let's try to know the parameter
value.
sort (object)
When supplied, sorts the results based on the provided criteria. Limitation: Currently only a single sort is allowed and is limited to last_edited_time
.
Search support sort function, and we Limitation phrase is noted.
It means only the last_edited_time option is available. Notion API will upgrade continuously, but only this option is available, so use it regularly. It means just like to be continued.
ascending
and descending
.last_edited_time
.Then how can we write code with the above sort option?
db_or_pages = notion.search(sort={"direction": "ascending", "timestamp": "last_edited_time"})
Like above, bind dictionary using {} and make the object.
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
)If you write code correctly, the filter option is available in one of two options.
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
maximum result is 100 cases. If the result exceed 100 cases, response will give "has_more" : True
and "next_cursor": "{unique id}"
values. Refer to next_cursor
, and into input start_cursor
value, you can search from 101st case and more.
page_size (int32)
The number of items from the full list desired in the response. Maximum: 100
You can set the case amount once. If you skip it, it will read the maximum cases, which is 100.
In conclusion, let's try full options and call the code with the search
method.
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)
If you feel this code is long, it's good to set variables and organize the code to improve readability.
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)