I need to create a subpage (sub-item) of a preexisting page inside a database in Notion using Notion API. I use Python to make API calls.
I tried to do a create page API call as described in the API documentation, but - even if Notion API answers with a "200 OK" code - I can only see the page as a subpage of the preexisting "parent" page when opening this last one in my notion view, but I can't see the page as a subpage (sub-item) in the table of the notion view I use to browse my database.
Here it is a picture of the preexisting pages/subpages hierarchy I'm trying to achive:
instead I can only see the newly created page by opening the "parent" page and looking at the bottom:
I'm looking for a way to make those subpages visible in my hierarchy as the previous ones showed in the first picture.
I already tried to do an update page API call to change the Sub item
property of the parent page or the Parent item
property of the child page, but even if the API call goes right (response with 200 OK code), those properties just remain the same... And no entry is added to the array of Sub items/Parent items.
Below I report an example of the payload I used in an update page
API call to update the Parent item
property of a newly created page trying to link it to the parent page:
{
'properties': {
'Parent item': {
'relation': [{
'id': '110a8a775e2a806dbc41c21dc16bfbda'
}]
}
}
}
And here it is the response I received after the previous request; as you can see no "Parent item" property was added...
{
"object": "page",
"id": "130a8a77-5e2a-816a-80ab-cf958857b90c",
"created_time": "2024-10-31T19:34:00.000Z",
"last_edited_time": "2024-10-31T23:39:00.000Z",
"created_by": {
"object": "user",
"id": "ab191a0a-ec55-4169-9601-e4e073adc04a"
},
"last_edited_by": {
"object": "user",
"id": "ab191a0a-ec55-4169-9601-e4e073adc04a"
},
"cover": null,
"icon": {
"type": "emoji",
"emoji": "🗓️"
},
"parent": {
"type": "page_id",
"page_id": "110a8a77-5e2a-806d-bc41-c21dc16bfbda"
},
"archived": false,
"in_trash": false,
"properties": {
"title": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "28/10/202403/11/2024",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "28/10/202403/11/2024",
"href": null
}
]
}
},
"url": "https://www.notion.so/28-10-202403-11-2024-130a8a775e2a816a80abcf958857b90c",
"public_url": null,
"request_id": "1701b627-9b65-400d-b5da-5d7460ef2dc5"
}
it only contais the parent page id inside the parent
property, but this property doesn't seem to be enough to make the page visible as subpage/sub-item in the database hierarchy I showed before.
My question seem to be related to this one, but that question didn't get an answer yet...
Does anyone have any ideas as to why this behavior occurs and can give me a hand?
I've found a solution to this.
It seems that to obtain a database with the hierarchy I showed in the pictures all the pages must have as parent
attribute the database itself and then be linked to their "parent page" through the Parent item
property.
So when doing the create page API call we need to set (for our newly created page) the database_id
key of the newly created page to the id
of the whole database and also set the Parent item
to the id
of the page we want as the "parent page" of our newly created page.
Thus the body(payload) of the create page request API call must look like the one below:
{
"parent": {
"type": "database_id",
"database_id": "baf6313070a14314a420b8160e062880"
}
"properties": {
"Parent item": {
"relation": [
{
"id": "110a8a77-5e2a-806d-bc41-c21dc16bfbda" #Id of the "parent page"
}
]
}
}
I think maybe the documentation is a bit misleading in this situation, because reading the create page API call doc. it seems that is enough/correct to set the parent
parameter of our request to the "parent page" id to link the newly created page to the page with that id and get such a hierarchy, while it is not actually the case.
As I couldn't find much information on this, I hope what I found can help developers working with Notion API and the whole community