I'm uploading images to a Trello Card using the Trello API. Trello by default set the image as the cover image. The API documentation says there is a setCover option but I cannot get it work.
https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post
def __upload_image_to_card(self, connection: dict, card: dict, image_path : str, cover=False):
params = (
('key', connection['trello_api_key']),
('token', connection['trello_api_token']),
)
values = {
'file': (image_path, open(image_path, 'rb')),
'setCover' : (cover),
}
# TODO: Move to node_manager
response = requests.post('https://api.trello.com/1/cards/%s/attachments' % card['id'], params=params, files=values).json()
I've tried switching between a boolean and string, have tried removing the brackets. I've even added a error key in values to see if I can get a different response. None stopped the image from being uploaded and none prevented the image from becoming the default image.
Would appreciate any help.
setCover
should be in params
, not in files
/values
. You may also need to make it str(cover).lower()
since it's expecting true/false
and not True/False
.
# since you using a list of tuples:
params = (
('key', connection['trello_api_key']),
('token', connection['trello_api_token']),
('setCover', cover),
)
Or as a dict:
params = {
'key': connection['trello_api_key'],
'token': connection['trello_api_token'],
'setCover': cover,
}