Page creation code (the commented out sections are marked as functional/nonfunctional - this is the source of errors):
\ndef create_page(k_title: str, \n k_id: str, \n k_col: str, \n k_url: str, \n k_cont: str, \n n_id: str, \n k_archive: bool, \n k_pinned: bool, \n kt_created: str, \n kt_deleted: str, \n kt_trashed: str, \n kt_updated: str,\n kt_edited: str, \n k_labels: list, \n peop_ref: list, \n k_list: bool,\n k_drawings: bool,\n k_images: bool,\n k_audio: bool,\n kd_text: str,\n ki_text: str,\n attached_media: str\n ) -> dict:\n \"\"\"\n Despite notation, k does not necessarily mean the keep value.\n \"\"\"\n temp_prop = {\n \"Title\": {\"title\": [{\"text\": {\"content\": k_title}}]},\n # This is a required property\n \n \"Keep ID\": {\"rich_text\": [{\"type\": \"text\", \"text\": {\"content\": k_id}}]},\n #uncertain if all of the rich_text definitions here are needed, but I'll keep for now.\n\n ################# PROPERTY BELOW DOES NOT WORK ################\n # \"Keep Color\": {\n # \"select\": {\n # \"options\": [{\"name\": k_col}]\n # #update this to be functional\n # }\n # },\n\n ################# PROPERTY BELOW DOES NOT WORK ################\n # \"Keep URL\": {\"type\": \"url\", \"url\": [{\"type\": \"text\", \"text\": {\"content\": k_url}}]},\n #Use the Keep ID to generate direct URLs to the notes in question. This will break for deleted notes\n \n \"Content\": {\"rich_text\": [{\"type\": \"text\", \"text\": {\"content\": k_cont}}]},\n #keep.text here\n\n \"Notion Identifier\": {\"rich_text\": [{\"type\": \"text\", \"text\": {\"content\": n_id}}]},\n #plug the notion identifier for the row here? if possible\n\n \"Archived\": {\"checkbox\": k_archive},\n #True or False; checking will archive\n\n \"Pinned\": {\"checkbox\": k_pinned},\n #True or False; checking will mark as pinned\n\n ################# ALL TIME PROPERTIES BELOW DO NOT WORK ################\n #\"Keep Created Timestamp\": {\"date\": [{\"text\": {\"content\": kt_created}}]},\n # \"Keep Deleted Timestamp\": {\"date\": [{\"text\": {\"content\": kt_deleted}}]},\n # \"Keep Trashed Timestamp\": {\"date\": [{\"text\": {\"content\": kt_trashed}}]},\n # \"Keep Updated Timestamp\": {\"date\": [{\"text\": {\"content\": kt_updated}}]},\n # \"Keep Edited Timestamp\": {\"date\": [{\"text\": {\"content\": kt_edited}}]},\n\n ################# PROPERTY BELOW DOES NOT WORK ################\n # \"Labels\": {\n # \"type\": \"multi_select\",\n # \"multi_select\": {\n # \"options\": [\n # k_labels\n # ]\n # },\n # },\n\n ################# PROPERTY BELOW DOES NOT WORK ################\n # \"People Referenced\": {\"people\": [{\"text\": {\"content\": peop_ref}}]},\n # #will become a link to Dex contacts eventually; sync into the notes there.\n\n \"Keep List\": {\"checkbox\": k_list},\n #True or False; checking will mark as List = True\n\n \"Keep Drawings\": {\"checkbox\": k_drawings},\n #True or False; checking will mark as Drawings = True\n\n \"Keep Images\": {\"checkbox\": k_images},\n #True or False; checking will mark as Images = True\n\n \"Keep Audio\": {\"checkbox\": k_audio},\n #True or False; checking will mark as Audio = True\n\n \"Keep Drawing Extracted Text\": {\"rich_text\": [{\"type\": \"text\", \"text\": {\"content\": kd_text}}]},\n #Content of DrawingText\n\n \"Keep Image Extracted Text\": {\"rich_text\": [{\"type\": \"text\", \"text\": {\"content\": ki_text}}]},\n #Content of ImageText\n\n ################# PROPERTY BELOW DOES NOT WORK ################\n # \"Attached Media\": {\"files\": attached_media},\n # #Keep now allows multiple types of media to be attached to a message; will need to account for this.\n }\n notion.pages.create(parent={\"database_id\": db_id}, properties=temp_prop)\n print(\"Database page created!\") #add in the database name and page title here. Maybe a time counter?\nTest variables for page creation code (sample inputs, returns the errors below):
\ntest_title = \"titling tester\"\nt_k_id = \"21.2135.51616\"\nt_k_color = \"Pink\"\n#Color Error reference:\n#https://github.com/ramnes/notion-sdk-py/issues/218\n\nt_k_url = \"https://google.com\"\nt_k_cont = \"lorem ipsum dolor sit amet yada yada ya\"\nt_n_id = \"ksug 278rt327tr\"\nt_archive = True\nt_pinned = False\nt_timestamp = \"2021-05-11T11:00:00.000-04:00\"\n#useful for datetime format:\n#https://github.com/ramnes/notion-sdk-py/discussions/129\n\nt_labels = (\"Sample Color 2\", \"Sample Color 3\")\nt_peop = \"G Man\"\nt_list = True\nt_drawings = True\nt_images = False\nt_audio = False\ntd_text = \"testting td\"\nti_text = \"blah blah bleh\"\nt_file = \"file link here?\"\n#I believe file uploads aren't allowed atm, switch this to a drive embed? or link?\n\ncreate_page(test_title, t_k_id, t_k_color, t_k_url, t_k_cont, t_n_id, t_archive, t_pinned, t_timestamp, t_timestamp, t_timestamp, t_timestamp, t_timestamp, t_labels, t_peop, t_list, t_drawings, t_images, t_audio, td_text, ti_text, t_file)\nResulting errors (just a sample, different but similar body-failed-validation error from each):
\nAPIResponseError: body failed validation. Fix one:\nbody.properties.Keep Created Timestamp.title should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.rich_text should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.number should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.url should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.select should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.multi_select should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.people should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.email should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.phone_number should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.date should be an object or `null`, instead was `[{\"text\":{\"content\":\"2021-05-11T11:00:00.000-04:00\"}}]`.\nbody.properties.Keep Created Timestamp.checkbox should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.relation should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.files should be defined, instead was `undefined`.\nbody.properties.Keep Created Timestamp.status should be defined, instead was `undefined`.\nbody.properties.Title.id should be defined, instead was `undefined`.\nbody.properties.Title.name should be defined, instead was `undefined`.\nbody.properties.Title.start should be defined, instead was `undefined`.\nAny help would be much appreciated!
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The error is raised by Notion's API (not the Python client), and is quite explicit:
\nbody.properties.Keep Created Timestamp.date should be an object or `null`, instead was `[{\"text\":{\"content\":\"2021-05-11T11:00:00.000-04:00\"}}]`.\nThe date fields don't expect a list of objects with a text key.
The documentation for this kind of property shows examples of what they're waiting for: https://developers.notion.com/reference/page-property-values#date
\nIIRC Notion only gives errors for one field at a time. So when you have validation errors with Notion's API:
\n-
|
Potentially associated with #218 I'm making a notion database that I need to push a lot of data in different properties/formats. I've used code examples/discussion solutions, but can't seem to get past errors similar to those in discussion/issue #218 - one of my issues (color) is a select property for the page that I couldn't get to work. I'm not sure if this is all an API issue/if that's been fixed since it was first raised, or just incorrect code on my part. I'd appreciate any thoughts and feedback! Database Creation Code (functional, no errors): Page creation code (the commented out sections are marked as functional/nonfunctional - this is the source of errors): Test variables for page creation code (sample inputs, returns the errors below): Resulting errors (just a sample, different but similar body-failed-validation error from each): Any help would be much appreciated! |
Beta Was this translation helpful? Give feedback.
-
|
The error is raised by Notion's API (not the Python client), and is quite explicit: The The documentation for this kind of property shows examples of what they're waiting for: https://developers.notion.com/reference/page-property-values#date IIRC Notion only gives errors for one field at a time. So when you have validation errors with Notion's API:
|
Beta Was this translation helpful? Give feedback.
The error is raised by Notion's API (not the Python client), and is quite explicit:
The
datefields don't expect a list of objects with atextkey.The documentation for this kind of property shows examples of what they're waiting for: https://developers.notion.com/reference/page-property-values#date
IIRC Notion only gives errors for one field at a time. So when you have validation errors with Notion's API: