Skip to content
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

Choose the order of column properties of a table created from the API #186

Open
sAZmed opened this issue Sep 8, 2020 · 4 comments
Open

Comments

@sAZmed
Copy link

sAZmed commented Sep 8, 2020

I'm trying to create some tables from a python script, however, whether I create it with specifying its schema or copying it from a pre-existing table (already created manually on notion), I can't choose the order of the columns. The columns of tables newly created or copied via the API are always automatically arranged in alphabetical order.

PS: I'm talking about the column order, not the row.

Thanks for all kind of help!

@TheSpeedM
Copy link

I ran into this problem too, so I looked at what Notion did in the browser when changing the order of the columns.
When sending an update of the order, it sends an transaction that, translated to python, looks like this:

client.submit_transaction(
    build_operation(
        id=collection_view_id,
        table="collection_view",
        path=[],    # i don't know what this one is for
        command='update',
        args={
            'format': {
                'table_properties': table_properties_
            }
        }
    )
)

table_properties_ is a list containing dictionaries of the properties, in order of desired column order.


That was probably too vague so i'll try to clarify with an example:
Let's suppose that we have three columns, that we want in the order: ['c2', 'c1', 'c3'], these are the schema names of the columns.

table_properties_ = [
     # Using list comprehension because it's easier here
    {'visible': True, 'property': schema_id} for schema_id in ['c2', 'c1', 'c3']
]

'visible': True and 'property' are the only properties necessary for this to work. You can also specify column-width ('width') in this request. (There are probably more extra properties but I haven't found them yet.)

@sAZmed
Copy link
Author

sAZmed commented Sep 30, 2020

Thanks, it has helped much!

@ag0n1k
Copy link
Contributor

ag0n1k commented Feb 7, 2021

The creation added in #274, but to sort and changed 'visible', maybe later.

@alexattia
Copy link

Thanks, but I have this issue when launching the code

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-276-e512b645186a> in <module>
     10                 'table_properties':  [
     11                          # Using list comprehension because it's easier here
---> 12                         {'visible': True, 'property': schema_id} for schema_id in ['control_reference', 
     13                                                                                    'date_of_execution',
     14                                                                                    'testor',

~/venv/lib/python3.7/site-packages/notion/client.py in submit_transaction(self, operations, update_last_edited)
    288         else:
    289             data = {"operations": operations}
--> 290             self.post("submitTransaction", data)
    291             self._store.run_local_operations(operations)
    292 

~/venv/lib/python3.7/site-packages/notion/client.py in post(self, endpoint, data)
    260             raise HTTPError(
    261                 response.json().get(
--> 262                     "message", "There was an error (400) submitting the request."
    263                 )
    264             )

HTTPError: Unsaved transactions: Space not found in record path

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

4 participants