Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Sort checkbox items alphabetically

Luyin I'm New Here Sep 10, 2020

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(
                    key=lambda x: x['name'].lower()
                item['pos'] = counter
                counter += 1
            print('updated checklist in order:')
            print(cl)    # for debugging

(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}",
    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?




3 answers

@Luyin as far as I know there is no 'set' for 'pos' on a checklist item. So you need to clear and add the items back

Here's what I did using py-trello

for cl in trello_card.checklists:
if == 'Checklist':
cl_dict = {}
for item in cl.items:
cl_dict[item['name']] = item['checked']
cl_dict_ordered = OrderedDict(sorted(cl_dict.items()))
for k in cl_dict_ordered.keys():
cl.add_checklist_item(name=k, checked=cl_dict_ordered[k])

# for verification only
test_dict = {}
for item in cl.items:
test_dict[item['name']]= item['checked']


{'C': True, 'S': False, 'F': True, 'A': False, 'G': False}
OrderedDict([('A', False), ('C', True), ('F', True), ('G', False), ('S', False)])
{'A': False, 'C': True, 'F': True, 'G': False, 'S': False}

I will probably convert this to a module that can be called via Butler HTTP Request to my Superhero Power endpoint with payload as {"card_id" : "{cardidlong}", "checklist_name" : "name of checklist"}

1 vote
Iain Dooley Community Leader Sep 10, 2020

@Luyin here's my implementation in Trellinator:

You can run that in BenkoBot here, just update the card link and the checklist name:

You can look at the implementation details/API calls in the Trellinator code:

@SGi Admin you can set position on Checklist items:

@Iain Dooley  Thanks. Will check py-Trello library. I know that there are some things I can do when coding custom Power Up using JS I cannot do with py-Trello especially the part on user-variables. 

Like Iain Dooley likes this

@Luyin this should be better. It preserves the checklist item "as is" . Important when advanced checklist assignment and due dates were set on the items.


for cl in trello_card.checklists:
if == 'Checklist':

sorted_cl_items = sorted(cl.items, key=lambda dict_items : dict_items.get('name'))

ix = 0
for i in sorted_cl_items:

# set pos to 6000++ and using Code block from py-trello def set_checklist_item(self, name, checked)

json_obj = client.fetch_json(
'/cards/' + +
'/checklist/' + +
'/checkItem/' + i['id'],
post_args={'pos' : 6000 + ix})

cl.items[ix] = json_obj
ix = ix + 1



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Trello

📹 What is Trello?

Hello Community!  My name is Brittany Joiner and I am a Trello enthusiast and Atlassian Community Leader. I'll be sharing with you a series of videos with my top tips on how to best use Trello...

817 views 13 30
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you