New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API to create new select item #51
Comments
Maybe it's not the most efficient, but I used the set schema method to implement this for myself with the following code: from uuid import uuid1
from random import choice
from notion.client import NotionClient
notion_client = NotionClient(token_v2=NOTION_TOKEN)
collection_view = notion_client.get_collection_view(NOTION_PAGE)
collection = collection_view.collection
colors = [
"default",
"gray",
"brown",
"orange",
"yellow",
"green",
"blue",
"purple",
"pink",
"red",
]
def add_new_multi_select_value(prop, value, color=None):
"""`prop` is the name of the multi select property."""
if color is None:
color = choice(colors)
collection_schema = collection.get("schema")
prop_schema = next(
(v for k, v in collection_schema.items() if v["name"] == prop), None
)
if not prop_schema:
raise ValueError(
f'"{prop}" property does not exist on the collection!'
)
if prop_schema["type"] != "multi_select":
raise ValueError(f'"{prop}" is not a multi select property!')
dupe = next(
(o for o in prop_schema["options"] if o["value"] == value), None
)
if dupe:
raise ValueError(f'"{value}" already exists in the schema!')
prop_schema["options"].append(
{"id": str(uuid1()), "value": value, "color": color}
)
collection.set("schema", collection_schema) Tagging #28 for duplicate. |
Hi, |
Okay so I managed to fix it. I think there were two problems :
|
Caution: running this crashed my table (beyond repair?). All I get now is the "oops! something went wrong"- page when I try to access it |
@nagamotoK That is weird, I still use a slight changed version of this in my bot every day. |
@bkiac thank you for the link/code. It seems, that the error was on my side. I used your implementation and now it works -- |
Automatic adding of missing options is now merged via #252 |
I want to add some new select item/tag to the select/multi-select property of a page. Is there anyway to do that ?
The text was updated successfully, but these errors were encountered: