Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the rows of a database in the order in which they're displayed?

I have some Python code that retrieves the rows in a Notion database using the notion-client library. The code does manage to retrieve all the rows, but the order is wrong. I looked at the Sort object from the API reference, but was unable to figure out how to use it to return the rows in the exact order in which they're displayed on notion.so. Here's the snippet in question:

from notion_client import Client

notion = Client(auth=NOTION_API_TOKEN)
result = notion.databases.query(database_id='...')
for row in result['results']:
  title = row['properties']['NAME_OF_PROPERTY']['title']
  if len(title) == 0:
    print('')
  else:
    print(title[0]['plain_text'])

What am I missing?

like image 214
feihong Avatar asked Nov 15 '22 21:11

feihong


1 Answers

The Notion API does not support views in the current version, so it is not necessarily going to match the order you have it in unless you have applied a sort or filter that you can also apply via the API.

like image 126
adlopez15 Avatar answered Jan 17 '23 02:01

adlopez15