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

How to set cover using butler HTTP requests

Death Vortex April 10, 2022

I am trying to copy the cover from one card to another using Butler HTTP requests. I was able to set the colors this way but when I tried setting the cover like this : Screenshot 2022-04-10 235023.png

It gives an error:

Screenshot 2022-04-10 235358.png

Since the file is already uploaded to trello shouldn't this be an allowed image service?

Is there any way I can set the cover? Is it possible by getting the attachment id? If so how?

2 answers

1 vote
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2022

Hello @Death Vortex 

As per the REST API documentation for the Update a Card endpoint, if you want to refer to an image using the url parameter, you can only refer images that are hosted in Unsplash for the cover:

url. Used if making an image the cover. Only Unsplash URLs work.

Urls to any other image location / place are not allowed.

To use an image that's attached to any card as the cover for any other card, you have to refer to it by its ID:

idAttachment. ID of an attachment on the card. Used if setting an attached image as the cover.

However, Butler currently does not have a variable such as {attachmentid} that will return the ID of an attached image, so there is no way to automate that aspect of the rule.

You are essentially stuck with having to manually put the ID of the image into your HTTP PUT request in your Butler rule:

{"key" : "[api_key]","token" : "[api_token]","cover" : {"idAttachment" : "ABCD1234etcetc","size" : "normal" }}

 Bummer, eh :)

Thomas May 11, 2022

Hi, @David Bakkers :

I was trying to find a getaround and I'm pretty sure it's possible but I may need some tweak.

My idea was:

  • Look up at the card I want the cover from
  • Get the cover attachment
  • Put this attachment as a new attachment of the destination card, defining it as a cover.

My rules look like this

Screenshot 2022-05-11 121649.jpg

It almost works as I have a new attachment in the destination card but it's not an image, so if I use "setCover": "true" in the last payload, I get the following error message.

Screenshot 2022-05-11 122921.jpg

 

Maybe @milynnus as some idea too?

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2022

@Thomas 

I don’t work with native Trello api a lot but based on your post, the issue is not the setcover but you did not get a image file as you indicated. 

I am able to get this if I make one of the attachment as a cover vs a cover that is taken from the unsplash. Same results when I used the python library and native api call.

Do note the url structure.

 

Screen Shot 2022-05-11 at 9.23.11 PM.jpg

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2022

@Thomas 

Creating the endpoint proves to be a bit more challenging than I thought.

  1. You cannot use the url because it complains about being unable to generate a preview.
  2. If you download and use the file, you cannot setCover at the same time

I have not done the documentation. Here's from redoc. Use the same endpoint from the documentation earlier in the post.

 

note: there is a 10s timeout which will affect large cover files. 

 

Screen Shot 2022-05-12 at 9.25.46 AM.jpg

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2022

Hello @Death Vortex @Thomas @milynnus 

Here is another approach on how to achieve using a card's attached image as its cover:

1. Attach an image to a card.

2. Do a Get request to that card to find the id of the attachment:

GET https://api.trello.com/1/cards/{cardid}/attachments?key=[yourKey]&token=[yourToken]

3. From the response, extract the id of the attachment as the variable {httpresponse[0].id} and store that in a custom field called "attachmentId"

4. Send a Put request to the same card and set the cover using that custom field's value:

PUT https://api.trello.com/1/cards/{cardid}

PAYLOAD {"key" : "[yourKey]","token" : "[yourToken]","cover" : {"idAttachment" : "{{%attachmentId}}" }}

 

Using a custom field to store the attachment's id from the response is a required work-around, since the variable {httpresponse[0].id} is treated as plain text for some reason, not a true variable, when used in the JSON payload of a Put request.

Also note that this method assumes that you have the image you want to use as the cover as the first attachment to the card

Thomas May 12, 2022

Thanks @milynnus

I'm not sure to understand what you did in 2 as I don't know what redoc is.

 

@David Bakkers 

thanks to you too but your approach works when the image is already attached to the card. In my case, I want to use an image from another card and the problem is that I'm able to copy an attachment from a card to another one but only as a link, not as an image. That makes the new attachment unavailable to use as a cover. I don't find the way to copy the image as an image.

From the Get request I don't get the image as data, which is what is expected according to the API

file

string

The file to attach, as multipart/form-data

Format: binary

I'm not an advanced coder, so I don't know if there is a way to get the image as data before setting it as an attachment to the new card.

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

@Thomas 

redoc is the documentation of the API. This is how you use it in a card button in Trello

create a new card with title "{triggercardname} : New" in list "Inbox", and post to url "https://moklxc.deta.dev/usecover?api_key=1......................7&token=be...............b4" with payload "{"card_id" : "{triggercardidlong}", "alt_card_id" : "{newcardidlong}"}"

Remember : use it with a trigger card that is using an attachment as its cover and not something from Unsplash.

BTW : I have updated the documentation 

https://github.com/xu2xulim/Superhero/blob/master/Superhero%20on%20deta/Micros/Attachments.md

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

@Thomas 

You can't just 'copy' an attachment from one card to another. Trello and the REST API's Create attachment on card endpoint expects you to create a new attachment per card, and you have to do that by supplying the file's data as multipart/form-data.

Unfortunately, the REST API's Get attachment on a card endpoint provides no mechanism of extracting the raw data of an existing attachment, only the information about it, like the id, date, bytes, name, url etc.

 

 

Using Custom Stickers as a Card cover

Maybe you need to re-think using attached images as the thing to put in the card cover and consider using a custom sticker instead. Once you create a custom sticker, it becomes an image that can be used 'universally' by all the cards on the board.

1. Create the custom sticker.

2. Drag the sticker into the cover of any card and position / rotate it to where you want it to appear for all cards.

3. Use a Get request to lookup the id and other information of the sticker:

GET from url : https://api.trello.com/1/cards/{cardid}/stickers?key=[yourKey]&token=[yourToken]

4. From the resulting {httpresponse} variable, take note of that sticker's id, the top and left offset, and the rotation degree.

NB. Once you know what a custom sticker's id is, you can store that piece of information offline to save having to look it up again in the future.

5. For any card you want that same sticker to be in the cover in that same position, do a Post request like this:

POST to url : https://api.trello.com/1/cards/{cardid}/stickers

PAYLOAD : {"key" : "[yourKey]","token" : "[yourToken]","image" : "[stickerId]","top" : "[topOffset]","left" : "[leftOffset]","rotate" : "0","zIndex" : "1"}

The good thing about stickers is that you can have many of them in the cover, all at different positions and rotation, which you can fine-tune via your POST request. You can also arrange their layering / overlap via the zIndex value.

The downside of stickers is that their size is pre-defined, and you can't scale them.

Thomas May 12, 2022

Thanks @David Bakkers 

I'm almost in the same position as before.

I mean. I created the custom sticker. I do get the expected results from the get request (I put it in a comment to ensure there was something usable) but when it comes to the POST part, it gives me an error: 

400 Error parsing body

This is the workflow.

Screenshot 2022-05-12 125202.jpg

I tried with httpresponse[0].image too, just in case but it has the same effect.

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

@Thomas 

I think you need to more closely read the information that is being provided.

I've already advised that you can't put {httpresponse[0].id} in a Put request's payload, because it gets parsed as ordinary text, hence the 400 Error parsing body error you got.

You have to actually type in the id of the sticker, directly into the payload:

{"key" : "123456blahblahblah","token" : "123456blahblahblah123456blahblahblah","image" : "627ca47368c7537ba17b6ec5","top" : "0","left" : "0","rotate" : "0","zIndex" : "1"}

.... as per the example I provided. 

If you don't want to manually type in that information into the payload, you have to put the sticker's id in an intermediate custom field, then use that custom field in the Put request payload:

{"key" : "123456blahblahblah","token" : "123456blahblahblah123456blahblahblah","image" : "{{%custom_field_that_holds_the_sticker_id}}","top" : "0","left" : "0","rotate" : "0","zIndex" : "1"}

 .... as described in the initial suggestion I provided.

Like Thomas likes this
Thomas May 12, 2022

Sorry @David Bakkers I'm not a native english speaker nor a good programmer and I sometimes don't understand everything.

After messing a bit around with all the info I finally got it. I just had to substitute the sticker id with the sticker image.

We'll work with that option for now, hoping that there we'll be an option to copy covers in the future.

Many thanks for your help 🙏🏻

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

No problem @Thomas 

Since stickers are relative to a board, once they are created, their id never changes. So, once you know what the id of a particular sticker is, you won't need it attached to a card just to 'extract' that id in the future, you can just store that id offline in a text file.

I've used this method to put custom stickers in card covers to signify changes in a card's status or importance. When combined with a cover color, it gives lots of combinations.

The main 'gotcha' of custom stickers is that they are the property of each board member, so even though a member can create them and then put them in a card cover, and the other members will see that sticker once it's in the cover, all those other members can do is move or remove it from the cover, they can't re-add it themselves as the source sticker won't appear in the Stickers panel. This usually means that the board admin has to be the custodian of any custom stickers that the team is going to collectively see for signifying card statuses.

Because custom stickers are owned by particular members, you can also lookup the ids of custom stickers using the Get a member's custom stickers endpoint, which returns all their stickers, so you have to be prepared to read / parse the whole response to know which particular sticker you are interested in.

Finally, if you are going to interact more with the Trello REST API, I suggest you get a test tool like Postman, so that you can create a collection of requests that you can run when you want, or to generally make test requests / do experiments to look at the results before transferring the request into Butler or another tool.

Have fun.

Like Thomas likes this
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

@David Bakkers @Thomas 

Interesting discussion on use of stickers. I will see I can add it to my collection of endpoints. It will be a lot easier to use since it will be just one http request. 

Update : Done

Difference for this endpoint is the path ...use /usesticker instead of /usecover

https://github.com/xu2xulim/Superhero/blob/master/Superhero%20on%20deta/Micros/Attachments.md

Like # people like this
0 votes
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2022
Thomas May 13, 2022

I, @milynnus . As I said, I'm no expert in this and I have some doubt.
Is it safe to send key & token as params for these requests?

Thanks

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2022

@Thomas 

It is fair to be concern. I don’t it is any difference in using Trello API. I think the fundamental difference is the provider of the third party service. In an earlier implementation I have registered users. So their credentials will be kept in a database or a .secret folder such that it will be called only during program execution. I have not incorporated it here so the service is without charge.

If you go into Trello Automation you will find your credentials in plain text. In my implementation I made sure that in Deta visor, the equivalent, it is not shown and based on their process they keep only the last 30 transactions for testing purpose. For production and better performance, visor is to be turned off. 

Not sure there is any added advantage but each trigger runs as a separate process in a serverless container environment. 

Like Thomas likes this
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2022

@Thomas 

For added assurance, you can host your own micro in Deta such that only you know the endpoint url, embedded your credentials in .env or Deta Base. I used python with a client but under the covers it calls the Trello Api. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events