Adding file to column via v2 API

Hi,

Trying unsuccessfully to upload a file to an existing column following the API docs, but I receive a Bad Request error without too much information regarding what is bad.

I’m working with Python, first I generate a request data:

req_data = “”“mutation{
add_file_to_column(item_id: %s, column_id: “%s”, $file: “%s”) {
id
}
}”“” % (item_id, column_id, self.to_base_64(fpath))

The file path is opened and then converted to a base64 string, this is the final request:

mutation {
add_file_to_column(
item_id: 724825528
column_id: “Files”
$file: “LHByb2plY3RfbmFtZSxncm91cAowLGJhdHJ1LAoxLGJpc2Vhc2ssCjIsY2JjZGFpcnlpbCwKMyxjY2JvdHRsZXJzdXMsCjQsY2Nici1wcm9kLAo1LGNjbGliZXJ0eXVzLAo2LGNjdHJhZG14LAo3LGRpYWdlb2FyLAo4LGRpYWdlb2JlbmVsdXgsCjksZGlhZ2VvaW4sCjEwLGRpYWdlb2l0LAoxMSxkaWFnZW9rZSwKMTIsZGlhZ2VvbXgsCjEzLGRpYWdlb25nLAoxNCxkaWFnZW9ub3JkaWNzLAoxNSxkaWFnZW9ydSwKMTYsZ3NrbnosCjE3LGluYmV2Y2ksCjE4LGluYmV2bmwsCjE5LGluYmV2dHJhZG14LAoyMCxtb25kZWxlemRtaXVzLAoyMSxuZXN0bGVpbCwKMjIscG5nanAsCjIzLHJpbmllbHNlbnVzLGdyb3VwX2EKMjQscmluaWVsc2VudXMsZ3JvdXBfYgoyNSxyaW5pZWxzZW51cyxncm91cF9jCjI2LHJpbmllbHNlbnVzLGdyb3VwX2QKMjcscmluaWVsc2VudXMsZ3JvdXBfZQoyOCxyd2ZhaXJwcnNnLGdyb3VwX2EKMjksc2Fub2ZpY2ksCjMwLHNhbm9maWNtLAozMSxzYW5vZmlqcCwKMzIsc2Fub2ZpbnosCjMzLHNhbm9maXNuLAozNCxzYW5vZml0ciwKMzUsc2h1ZmVyc2FsaWwsCg==”
) {
id
}
}

I am sending it as a POST to the /v2/file API, I can add items and do other manipulations, it’s just that this query keep failing with Bad Request.
I tried omitting the $ in $file, tried escaping it, nothing worked.

Thanks.

Hey @aviadm - welcome!

Right now you wouldn’t be able to upload the file this way - it would need to be sent over as a multipart file. We’re working on having more documentation on this, but in the meanwhile I would recommend following this guide from our community.

Let me know if we can help with anything else.

-Daniel

Any update to this? I tried reading the community guide but I am still having trouble getting it to work and formatting it correctly with Python.

Hello @Knowa,

We recently pushed out a new release of moncli that includes uploading files to a column or update.

The readme contains documentation regarding this, but the below code example may help get things started:

>>> from moncli import MondayClient
>>> 
>>> client = MondayClient('username', '', 'api_v2_key')
>>> board = client.get_board(id='board_id')
>>> item = [item for item in board.get_items() if item.id == 'item_id'][0] # Keyword arguments to be supported soon.
>>> file_column = item.get_column_value(id='column_id')
>>> file_asset = item.add_file(file_column, 'upload_file_path')

Best of luck, and please let me know if you have any questions.

All the best!

1 Like

Interesting, I will check this out. I tried using moncli a couple months ago but had an issue with a complexity error when querying groups. I’ll let you know if I have any issues.

Hey @Knowa - at this time the multipart upload I listed above would still be the main way to upload files to the API (you can use something like Postman for this).

I haven’t personally tried the new release of moncli above, but I’d be curious to hear your results :slight_smile:

-Daniel

When using what you posted, when I use board.get_items(), I get a TypeError for an unexpected keyword argument ‘ids’. This is also true for other variations of ‘ids’.

client = MondayClient(user_name='EMAIL', api_key_v1='', api_key_v2='APIV2KEY')

board = client.get_board(id='123456789')

item = board.get_items(ids=[790942328])  

    File "c:\Python38\Scripts\Projects\mondayTest.py", line 10, in <module>
        item = board.get_items(ids=[790942328])
TypeError: get_items() got an unexpected keyword argument 'ids'

Hello @Knowa,

I must apologize. The current release does not support keyword arguments for get_items() :frowning_face:. You can work around this with list comprehension.

item = [item for item in board.get_items() if item.id == '790942328'][0]

I have been side-tracked by other work-related projects and am actually looking into the complexity issue that you submitted earlier. I will add the keyword argument support for this in the meantime.

I know that our current dev codebase (for the official release) does support keyword arguments for these types of query methods. I will be working on getting this released within the next week or two.

Thank you for your patience, and please let me know if this works out for you!

1 Like