2

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?

Akshaya D N
  • 49
  • 1
  • 4
  • Found a temporary solution: Just add a while loop to send the POST request until the response code is 200. Works perfectly – Akshaya D N May 19 '21 at 19:26

3 Answers3

4

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.

dju
  • 55
  • 4
  • No. I hadn't done that. I guess the problem was adding "type":"database_id". After removing it, everything is working fine. – Akshaya D N May 22 '21 at 18:34
2

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.

Akshaya D N
  • 49
  • 1
  • 4
0

I was able to fix this error by editing the headers of the request.

headers = {
    "Accept": "application/json",
    "Notion-Version": "2022-06-28",
    "Content-Type": "application/json",
    "authorization": "Bearer {token}"
}

Adding the "Content-Type": "application/json" to the headers is what fixed it.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77