Skip to content

QUESTION - Is there a way to add a property to an already existing collection? #242

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

Closed
aviral-batra opened this issue Dec 18, 2020 · 2 comments

Comments

@aviral-batra
Copy link

I don't know where else to ask, I was wondering how you can add a property to an existing collection?

@aviral-batra
Copy link
Author

I found the answer myself:

If you edit the data structure of a block/collection, then you can sync it to notion using set, i.e. to add a new property:

cvb = client.get_block(collection_view_block_url)

# inserts a new property into the cached dictionary
cvb.collection.get()['schema']['NewProp'] = {
    "name": 'New property',
    "type": 'text'
}

# loads the cached schema into a variable to make it easier to manipulate
schema = cvb.collection.get()['schema']

# syncs the locally cached schema to the notion server
cvb.collection.set(path=['schema'], value=schema)

N.B. if you add force_refresh=True in the get method before you set the dictionary, you will get the original i.e. the one stored in the actual notion database, not the cached one. Until you use set(), the structure/collection/block is not updated.

@ag0n1k
Copy link
Contributor

ag0n1k commented Feb 7, 2021

#274 added more clear interface to create property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants