1

I am currently trying to update a value in a Notion Data base but i am only able to update the header row and not the value fields. Also when getting a specific database using its id only the header values are returned and not the values that are inside the data base. This is the code i am currently using to update the data base header value

payloadUpdateDataBase = {"properties":{"Ticket ID":{"name": "New Ticket ID"},},}

headers = {
"Authorization": "Bearer " + token,
    "Accept": "application/json",
    "Notion-Version": "2022-02-22",
    "Content-Type": "application/json"
}

def updateDatabase():
    response = requests.request("PATCH", urlSingleDataBase, json=payloadUpdateDataBase, headers=headers)
    print(response.status_code)
    print(response.text)

Does any one know how to get/update the values inside the database and not only the headers?

ChapN
  • 11
  • 1
  • 3

2 Answers2

0

Every entry within a database is a page itself and can be as such manipulated using the usual pages endpoint. By querying the database, you can get the page_id needed to do so. On the other hand, each entry can be treated as a block. If you want to manipulate the content and different child blocks, you can use the page_id as block_id for the blocks endpoint.

Simon
  • 126
  • 2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/late-answers/32623801) – Deenadhayalan Manoharan Sep 08 '22 at 09:33
  • It does indeed provide the answer to his question - by updating the pages you'll update the values inside the database. – Simon Sep 09 '22 at 10:43
0

The readme.md file in the pynotion project has more information about this, but you can use:

from notion.client import NotionClient

client = NotionClient(token_v2="<your token>")
cv     = client.get_collection_view("<The url of your table>")

for i in rows:
    if i.get_property("Name") == "<The name of the row you want to modify>":
        i.set_property("State", "To-do")

Unfortunately, the main repository is not being maintained for the past 2 years, so there's a bug preventing the prior code to run, but it can be easily fixed following this Github comment!

Aditionally, you can get the available properties and their options in a programatic way with:

props = cv.collection.get_schema_properties()
egeres
  • 77
  • 3
  • 9