Adding pages to a multi-column notion database works flawlessly sometimes and gives a validation error sometimes for the same input

Viewed 3041

Basically, I'm using Postman to send POST requests to

https://api.notion.com/v1/pages

It works for 70% of the times and rest of the times it gives the following error sometimes. That is, for the same input.

{
    "object": "error",
    "status": 400,
    "code": "validation_error",
    "message": "body failed validation. Fix one: body.parent.type should be not present, instead was `\"database_id\"`. body.parent.page_id should be defined, instead was `undefined`."
}

Here's how my body starts

{
    "parent": {
        "type": "database_id",
        "database_id": "a94c42320ef04b6a9c1a7e5e73455557"
    },
    "properties": {
        "Title": {
..................

I'm not posting the entire body because it works flawlessly sometimes.

Please help me out. Is there a way to check logs of the requests that come to my page?

2 Answers

First, I found out that type: database_id is not necessary in parent.

I also found out that syntax errors in the payload returns a 400 error:

body failed validation. Fix one: body.parent.type should be not present, instead was `\"database_id\"`. body.parent.page_id should be defined, instead was `undefined`.

In my case, I wrongly added a value in the same level as parent, properties. Like this:

{
    "parent": {
        "database_id": "<database_id>"
    },
    "properties": {
        ...
    },
    "wrong_value": {}
}

Since the errors are not that specific, check if you made the same misktake like me, and please also double check if the parent you are trying to post to is actually a database, not a page.

The issue was with having "type: database_id" inside "parent" in the request data.

{
    "parent": {
        "type": "database_id",(REMOVE THIS LINE)
        "database_id": "a94c42320ef04b6a9c1a7e5e73455557"
    },
    "properties": {
        "Title": {
..................

After removing "type" it worked fine. Notion needs to update their docs.

Related