ramnes / notion-sdk-py

The official Notion API client library, but rewritten in Python! (sync + async)
https://ramnes.github.io/notion-sdk-py
MIT License
1.75k stars 138 forks source link

Create database entry with `select` property #218

Closed baniasbaabe closed 9 months ago

baniasbaabe commented 9 months ago

I created the following database:

{'object': 'database',
 'id': '59cd91df-4140-4a0a-bbeb-1fa5a8709ef2',
 'cover': None,
 'icon': {'type': 'emoji', 'emoji': '🎉'},
 'created_time': '2023-12-05T12:33:00.000Z',
 'created_by': {'object': 'user',
  'id': '1e824c3d-4b46-449a-b5a8-776a9cf9ee97'},
 'last_edited_by': {'object': 'user',
  'id': '1e824c3d-4b46-449a-b5a8-776a9cf9ee97'},
 'last_edited_time': '2023-12-05T12:33:00.000Z',
 'title': [{'type': 'text',
   'text': {'content': 'LinkedIn Posts Template', 'link': None},
   'annotations': {'bold': False,
    'italic': False,
    'strikethrough': False,
    'underline': False,
    'code': False,
    'color': 'default'},
   'plain_text': 'TestDatabase',
   'href': None}],
 'description': [],
 'is_inline': True,
 'properties': {'Status': {'id': 'm%3A~K',
   'name': 'Status',
   'type': 'select',
   'select': {'options': [{'id': 'f7b07d74-2a53-45a1-b46c-e17d13cc405e',
      'name': 'To Do',
      'color': 'blue'},
     {'id': 'cb250430-8e68-4b26-96af-930195434058',
      'name': 'Working',
      'color': 'yellow'},
     {'id': 'fad49bfe-13d8-4498-9300-490a97ea2602',
      'name': 'Done',
      'color': 'red'}]}},
  'Title': {'id': 'title', 'name': 'Title', 'type': 'title', 'title': {}}},
 'parent': {'type': 'page_id',
  'page_id': 'b63ecd4f-b794-4063-a6ef-5f3a6820c1be'},
 'url': '<URL>',
 'public_url': None,
 'archived': False,
 'request_id': '49502c30-9fc6-48a7-a8a4-f73134a3e868'}

Now, I wanted to create an entry like so:

notion.pages.create(**
 { 
    "parent": 
     { "database_id": "59cd91df-4140-4a0a-bbeb-1fa5a8709ef2" }, 
    "properties": 
     { "title": 
      { "title": [ { "type": "text", "text": { "content": "Template1" } } ] }, 
       "Status": {"type": "select", "select": [{"name": "Template"}]} 
       } 
    })

which throws the following error:

APIResponseError: body failed validation. Fix one:
body.properties.Status.title should be defined, instead was `undefined`.
body.properties.Status.rich_text should be defined, instead was `undefined`.
body.properties.Status.number should be defined, instead was `undefined`.
body.properties.Status.url should be defined, instead was `undefined`.
body.properties.Status.select should be an object or `null`, instead was `[{"name":"Template"}]`.
body.properties.Status.multi_select should be defined, instead was `undefined`.
body.properties.Status.people should be defined, instead was `undefined`.
body.properties.Status.email should be defined, instead was `undefined`.
body.properties.Status.phone_number should be defined, instead was `undefined`.
body.properties.Status.date should be defined, instead was `undefined`.
body.properties.Status.checkbox should be defined, instead was `undefined`.
body.properties.Status.relation should be defined, instead was `undefined`.
body.properties.Status.files should be defined, instead was `undefined`.
body.properties.Status.status should be defined, instead was `undefined`.
body.properties.title.id should be defined, instead was `undefined`.
body.properties.title.name should be defined, instead was `undefined`.
body.properties.title.start should be defined, instead was `undefined`.

When I remove the Status property, it works fine (see image below):

image

I can' see where the mistake is since I copied and adapted it from other issues and discussions. I also tried different names of Status like status, tags and so on.

Originally posted by @baniasbaabe in https://github.com/ramnes/notion-sdk-py/discussions/217

ramnes commented 9 months ago

This is not an error from notion-sdk-py but from Notion's API, so let's keep it as a discussion for now.