resturllib3trello

How to set the color of a card cover in Trello API?


Problem Summary:
Having trouble changing Trello card cover color.

Similar Questions in StackOverflow
Nearly identical question here. I've tried the answer offered on that post without success. Symptoms are similar to what follows below.

Technologies in Use


What I have tried:
I am using the Update A Card service from the Trello API. This service formed like this:

https://api.trello.com/1/card/24CHARCARDNO?key=32CHARKEY&token=64CHARTOKEN&cover={"color:","green"}
---------------------- - ---- ------------     ---------       ----------- ------------------------
     URL END POINT     |  |       |                |                 |                 |
                       |  |       |                |                 |                 |
API VERSION------------+  |       |                |                 |                 |
                          |       |                |                 |                 |
API-----------------------+       |                |                 |                 |
                                  |                |                 |                 |
WHICH CARD -----------------------+                |                 |                 |
                                                   |                 |                 |
APP KEY -------------------------------------------+                 |                 |
                                                                     |                 |
USER AUTHENTICATION TOKEN -------------------------------------------+                 |
                                                                                       |
PAYLOAD TO CHANGE CARD COVER COLOR ----------------------------------------------------+

In both cases, I get what looks like good JSON back from Trello, but the card does not actually get the assigned color. What is interesting is that the return JSON shows that the attribute on the card has not changed. In the snippet below, I sent "pink" for the color, but the returned JSON says "green". Is Trello colorblind? ;-)

"cover": {
    "idAttachment": null,
    "color": "green",
    "idUploadedBackground": null,
    "size": "full",
    "brightness": "light"
},

How you can help

I've been looking for examples of the use of the Trello API for this attribute, but I've not seen anything working and the documentation is the only source of truth I have. Can anyone point me at an example, or perhaps point out the obvious thing I'm missing?

Thanks,

Paul


Solution

  • So the problem is that the color has to be passed in the body of the request. The formation I tried above is correct for a GET but not for a PUT. So here is the resulting syntax:

    curl -H 'Content-Type: application/json' -X PUT -d '{"cover" : {"color":"pink"}}' 'https://api.trello.com/1/cards/24CHARCARDNUMBER?token=64CHARTOKEN&key=32CHARKEY'
    

    Pay special attention to where ' and " belong.

    Note that though JSON might officially accept square brackets for a single element array, the Trello API did not like it:

    {"cover" : ["color":"pink"] } does not work, but {"cover" : {"color":"pink"}} does work.