Trello Rest API - Card Colors/Covers

Apologies if this has been asked/answered; I didn’t find any threads.

Will the Rest API be updated to allow for control over a card’s cover/color?

2 Likes

Great question! It isn’t documented yet (on my to-do, I promise!).

Let me see if I can’t give a rough outline of it here:

On a PUT to /1/cards/{idCard} you can pass in a cover key and object with the following option key/values:

Option Values About
color pink, yellow, lime, blue, black, orange, red, purple, sky, green Makes the cover a solid color .
brightness dark, light Determines whether the text on the cover should be dark or light.
url An unsplash URL: https://images.unsplash.com Used if making an image the cover. Only Unsplash URLs work.
idAttachment ID of an attachment on the card Used if setting an attached image as the cover.
size normal, full Determines whether to show the card name on the cover, or below it.

brightness can be sent alongside any of the other parameters, but all of the other parameters are mutually exclusive; you can not have the cover be a color and an idAttachment at the same time.

On the brightness options, setting it to light will make the text on the card cover dark:
05%20PM

And vice versa, setting it to dark will make the text on the card cover light:
31%20PM

Additionally, we added a setCover to the attachments POST endpoint that accepts a Boolean value. If true the attached image will be made the card cover.

POST https://trello.com/1/cards/{idCard}/attachments

{
  file: [fileData],
  setCover: true,
}
1 Like

Perfect! That’ll do for me for now! Thank you!

Also, anything on your roadmap that will allow custom RGB values for card covers? Considering the brightness setting, I think this would be an awesome and useful option!

Thanks again!

As far as I know, that isn’t on the roadmap right now.

But I’ll happily pass along the idea! :slight_smile:

Hey @bentley

I tried this today but was not able to set the cover on the card, can you confirm current API supports this?

Yes, I’m certain the API supports this. Here is the blog announcing this feature: How (and why) to customize Trello board card covers and colors | Trello.

If you open your browser’s network tab and watch the requests made by the Trello web client to the server, you’ll see a cover object in the payload when you make changes to the card cover via this widget on the right of the card back:

The API documented and available to you is the same one that the web client (and mobile clients!) use, as well.

I’m also not able to get this API endpoint to work.

I’m confused re how & what format I need to provide the cover info.

I can easily change items such as ‘desc’ (which are string format), but per API reference card is an object.

For example, (and i’m using python), using the sample code in the URL above, I can update say the ‘desc’ by adding ‘desc’: ‘updated text in desc field’ to the query dictionary.

But I cant work out how to update the ‘cover’. Getting card data, it appears ‘cover’ is a dictionary in python, as I get the following in response.text
“cover”:{“idAttachment”:null,“color”:null,“idUploadedBackground”:null,“size”:“normal”,“brightness”:“light”}

I’ve tried passing a cover dictionary via the query. eg attempting to set cover to purple:
‘cover’: {‘idAttachment’: None, ‘color’: ‘purple’, ‘idUploadedBackground’: None, ‘size’: ‘normal’, ‘brightness’: ‘light’}

How should the cover be specified in the put request’s query parameter ?

@DennisEagles @bentley
I am facing same issue. Tried to update card cover color but even though I am getting success response, card cover is not updating. Below is the screenshot of the PUT request. Please suggest.

@GauravSrivastava @DennisEagles
I am using VSCode “REST.Client” add-in REST Client - Visual Studio Marketplace to work with the Trello API.

The following test_trello.http file to update a Trello card worked for me.
Getting a status code of 200 with updated card info.

Update the variables.

###
@trello_api = https://api.trello.com

@trello_token = 70XXXXXXXXXXb2
# This grants access to the data. This needs to be KEPT SECRET.
# On the same page as https://trello.com/app-key, click the hyperlinked "Token" under the API key.
# click "Allow".

@trello_key = 5XXXXXXXXXXXXXXXXXXXXXXXXc
# You can get your API key by logging into Trello and visiting https://trello.com/app-key
# An API key by itself doesn't grant access to a user's Trello data and could be public.

@trello_card = 5XXXXXXXXXXXXXXX6
# Get the card ID by opening a card on your test Trello board, then delete the name in URL and add .json to the URL, press enter to get a web page with card data, including card ID.

###
# Let check that PUT call is working with simple card name change
PUT {{trello_api}}/1/cards/{{trello_card}}?key={{trello_key}}&token={{trello_token}}  HTTP/1.1
content-type: application/json

{
    "name":"Let us change the name to test PUT."
}

###
# Update card cover colour

PUT {{trello_api}}/1/cards/{{trello_card}}?key={{trello_key}}&token={{trello_token}}  HTTP/1.1
content-type: application/json

{
"cover":{
            "color":"purple",
            "idAttachment":null,
            "idUploadedBackground":null,
            "size":"normal",
            "brightness":"light"
            }
}
1 Like

@RudigerWolf Thank ou Rudiger. Adding content-type: application/json solved my issue.

Interesting … I was using the example code from Atlassian trello api docs and couldnt get it to work … but with the help of a genius on stackoverflow was able to get it working by passing a ‘json’ parameter in the request with the cover stuff, in addition to the ‘params’ parameter with the key/token.

Does the API support changing the style of the cover (as seen in the blogpost)? Haven’t found anything about changing the style of a card in the docs, but I could just have been looking in the wrong places.

This is bizarre, flipped logic. The option description above it says:

brightness  `dark` , `light` Determines whether the text on the cover should be dark or light.

So by making the text ‘light’ it comes out black, and by making it ‘dark’ it comes out white?

Really, brightness refers to the brightness of what’s BEHIND the text, and you’re setting the color of the text to be the opposite.

1 Like

Hi @bentley,

Thanks for this information, it has been very useful. I think a recent change with unsplash has perhaps made the image cover no longer function.

When I use the image URL from unsplash, in this instance black sailing boat digital wallpaper photo – Free Boat Image on Unsplash

I get an error “400 url must be from an allowed image service”

If I has images before the domain, that is https://images.unsplash.com/photos/DKix6Un55mw

I instead get an error “400 Failed to get image from url”.

I assume based on these two errors that the api is looking for “images.unsplash” to validate that it is an allowed service. However it seems unsplash may not be using this address.

Keen for your insight!

Cheers
Shane

This is a very neat function but I cannot find any method to remove the Cover from a Card once it is set. Is it possible via the API?

1 Like

@JonasHertz Passing {"cover": ""} as the json payload seems to work.

2 Likes

Thank you, thank you, thank you. I thought I tried every combination. Now I just need someone to fix all the head-shaped holes in my walls.

1 Like

A post was split to a new topic: Question about POSTing with card covers