I would like to build a function (via API or Power-Up; I would slightly prefer to use the API, because it lets me exercise coding) that lets me sort items in a checklist on a card alphabetically. So my idea is that I have two functions:
f(checklist) -> sorted(checklist_items)
g(sorted_checklist_items, board) -> PUT (update checklist item order on board)
The first one I got to work with this:
for c in cards_with_checklists:
if c['shortLink'] in TO_BE_SORTED:
print(c['name'], c['shortLink'])
print('shortLink is correct, entering checklist sorting')
checklists = (get_checklist(id) for id in c['idChecklists'])
for cl in checklists:
counter = 0
for item in sorted(
cl['checkItems'],
key=lambda x: x['name'].lower()
):
item['pos'] = counter
counter += 1
print('updated checklist in order:')
print(cl['name'])
print(cl['id'])
print(cl) # for debugging
print()
break(I pasted this from a jupyter notebook, so it's not 100 % refactored)
For the second one I used this:
def update_checklist(id) -> None or requests.exceptions.HTTPError:
response = requests.put(f"{trello_api}/checklists/{id}",
params=q)
return response.raise_for_status()The code runs through, with a 200 OK code, but the items on the card didn't get updated on the board (not even after refreshing the page, clearing the cache and similar movements. That makes me wonder whether I misunderstood the logic of the 'pos' attribute on checklist items.
Is there anyone who has built something similar and has succeeded?
BR
Luyin