2

I'm trying to create a new page in a database in notion. Here is my code:

data = {
      "parent": {"database_id": parent},
      "properties": {
          "Name": {
            "title": [{"type": "text", "text": {"content": assignment}}]
          },
          "Class": {
              "rich_text": [
              {
                "text": {
                  "content": class_name
                }
              }],
          },
          "Due Date": {
            "date": {"start": "2021-05-11"}
          },
          "Tags": {
              "multi_select": [
                  {"name": class_tag}
                ]
              },
          "Class Schedule Entry": {
              "relation": [
                  {
                      "id": assignment_id
                  }
              ]
          }

      }
}
if prof:
    data['Professor'] = {
              "rich_text": [
                  {
                      "text": {
                          "content": prof
                      }
                  }],
          }
print(data)
response = requests.request("POST", notion_page_url, json=data, headers=headers).json()

"parent" variable contains the database id and I have confirmed that it is correct. "notion_page_url" variable contains "https://api.notion.com/v1/pages/"

The error that I get is:

{'object': 'error', 'status': 400, 'code': 'validation_error', 'message': 'body failed validation: body.parent.page_id should be not present or a string, instead was null.'}

According to the docs, we are suppose to include either a database_id or a page_id in parent and I've included a database_id.

Any ideas?

lovefaithswing
  • 1,510
  • 1
  • 21
  • 37
  • Recommend printing out the entire request to see what your code is generating. It should look something like this: ``` curl --location --request POST 'https://api.notion.com/v1/pages' \ --header 'Content-Type: application/json' \ --header 'Notion-Version: 2021-08-16' \ --header 'Authorization: Bearer YOUR_TOKEN' \ --data-raw '{ "parent": {"page_id": "YOUR_PAGE_ID" }, "properties": { "title": [{"text": {"content": "test_page"}}] } }' ``` – adlopez15 Oct 14 '21 at 19:43

0 Answers0