Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,296,559
Community Members
 
Community Events
165
Community Groups

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

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

@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. 

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": ""
  }
]

@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.

@Kalvin Lyle 

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

@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

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}"

Hmm scratch that, it works sometimes...

@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.

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Trello

Taco Tuesday: New years' resolutions with Trello

Congratulations to @Laura Holton , our latest winner of Taco Tuesday! And thanks to @Kristján Geir Mathiesen for sharing the picture of Taco having fun with his new friend  B...

2,335 views 28 40
Join discussion

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