Notion API master series 22 - Analysis - Retrieve a database & Retrieve a user

소찬 (Chan)·2022년 12월 6일
0
post-thumbnail

Reference URL : Retrieve a database, Retrieve a user

We try to retrieve for getting database information.
Use the search method for bringing database_id.

databases = notion.search(filter={"property": "object", "value": "database"})
pprint(databases)

The result shows databases which API Bot has rights. Get the id value of the database that you need.

{'has_more': False,
 'next_cursor': None,
 'object': 'list',
 'page_or_database': {},
 'results': [{'archived': False,
              ... ,
              'icon': {'emoji': '🍕', 'type': 'emoji'},
              'id': '021eb424-7a41-47ae-9252-f67d4f6e6b05', # database_id

Likewise, 'results' is a list, so if you want to get the first 'id', bring [0]th value, second is [1]st value. First of all, the example is obtaining the first id of the database.

database_id = databases['results'][0]['id']

Now retrieve data with the above database_id and bring information.

database_details = notion.databases.retrieve(database_id=database_id)
pprint(database_details)

And see database information which retrieved, like below, 'id' exists which is a form of UUID(Universal Unique IDentifier). We cannot identify from the UUID form, so API provides the function for getting information with this user's id.

'created_by': {'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b', 'object': 'user'},

Firstly, get 'created_by' and 'user_id' from database_detail

created_user = database_details['created_by']['id']

Now try to retrieve with this 'id'.

created_user_info = notion.users.retrieve(user_id=created_user)
pprint(created_user_info)

Print and the value shows username and email information.

{'avatar_url': None,
 'id': 'edfacc72-eb15-467b-9fdb-d5b656e1c77b',
 'name': 'Chan Chan',
 'object': 'user',
 'person': {'email': 'chanbaek@kakao.com'},
 'type': 'person'}
profile
QA Specialist

0개의 댓글