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

get last attachment ID when returning {httpresponse} with Butler?

Kalvin Lyle March 29, 2022

I'm trying to get the last attachment on a card in Butler. When I GET the card attachments I can't seem to parse the JSON to get the last attachment.

I'm using this automation:

when an attachment is added to a card by anyone, get url "https://api.trello.com/1/cards/{cardid}/attachments/?key=[KEY]&token=[TOKEN]", and set the card's description to "{httpresponse}"

The JSON result pastes into the description nicely, but anything I do to try to parse it returns an INVALID JSON.

Any ideas?

1 answer

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.
March 29, 2022

@Kalvin Lyle 

{httpresponse} is probably a list of dictionaries. So you might need {httpresponse}[-1].url … Try it. If I have time I will investigate further. 

Kalvin Lyle March 31, 2022

the array is within the {...}, but {httpresponse[0]} does not work.

The returned JSON structure looks like this:

 

[
  {
    "id": "",
    "bytes": ,
    "date": "",
    "edgeColor": "#",
    "idMember": "",
    "isUpload": ,
    "mimeType": "",
    "name": "",
    "previews": [
      {},
      {},
      {}
    ],
    "url": "",
    "pos": ,
    "fileName": ""
  }
]

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.
March 31, 2022

@Kalvin Lyle 

It seems that you can get to an array for an item in a dictitionary but not to a dictitionary inside an array/list aka a list of dictitionaries.

https://help.trello.com/article/1203-issuing-http-requests-with-butler

Having said that you can use http request to an endpoint that will provide you what you need. 

Here I have an example for attachments :

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

Currently it has only one endpoint.

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.
March 31, 2022

@Kalvin Lyle 

If you are testing out the endpoint you should be using {cardidlong} instead of {cardid}

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.
March 31, 2022

@Kalvin Lyle 

Updated the endpoint with the following payload (an example) :

{
"card_id": "{triggercardidlong}",

"alt_card_id": "{newcardidlong}",

"option" : ""
}

where option can

"" -  all attachments,

"first" - the first attachment added on the source card or

"last" - the last attachment added on the source card

Kalvin Lyle April 1, 2022

All the magic is happening in Butler. This seems to work now:

when an attachment is added to a card by anyone, get url "https://api.trello.com/1/cards/{cardid}/attachments/?key=[KEY]&token=[TOKEN]", and set the card's description to "{httpresponse[0].name}"

Kalvin Lyle April 1, 2022

Hmm scratch that, it works sometimes...

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 1, 2022

@Kalvin Lyle 

That's good news. Will you be trying to copy the attachment over or just to get the name.

Do you know if the last attachment is a cardlink or boardlink, will the above still work. In my work, I need to filter those out since they are part of the returned array of attachments.

Kalvin Lyle April 1, 2022

My plan was to set the card cover by getting the last attachment id using {httpresponse} but this seems not possible using Butler. I can get the last attachment by getting {httpresponse.Badges.Attachments} from the card to get the length, but it doesn't seem possible to subtract 1 from that number to get the last attachment.

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 1, 2022

@Kalvin Lyle 

Got it to work

Screen Shot 2022-04-01 at 6.36.42 PM.jpg

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events