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,294,581
Community Members
 
Community Events
165
Community Groups

Butler HTTP requests - how to loop results in returned JSON

I am trying to help someone automatically populate some information into a card each morning. Since a HTTP API is available to fetch the data as a JSON, it seems we should be using Butler:

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

The example provided helped to get a proof of concept working, but it only shows how to display a specific result 

First result: {httpresponse.relatedMovies[0].title}

The data I am requesting may return any number of results, from 0 to 30, so listing each is not practical and would result in 'undefined' being displayed if results were not available; following the example, perhaps you want to return the list of all the movie titles that are related with no limit; the below is not ideal:

First result: {httpresponse.relatedMovies[0].title}
Second result: {httpresponse.relatedMovies[1].title}
Third result: {httpresponse.relatedMovies[2].title}
Fourth result: {httpresponse.relatedMovies[3].title}
...

I assume there is some wildcard or the ability to do a for loop of some sort?

for {let n = 0; n < httpresponse.relatedMovies.length; n++}
{
{httpresponse.relatedMovies[n].title}
}

Any help appreciated. I had a decent search through the documentation and forum and didn't find anything related. Perhaps we need to move to the Power Ups to get this sort of functionality?

The above considers a JSON like in the example on the link

{
relatedMovies:[
  {title: 'Movie 1'},
  {title: 'Movie 2'},
{title: 'Movie 3'},
{title: 'Movie 4'}, ], };

 

3 answers

1 accepted

0 votes
Answer accepted

Thank you for your responses, although largely confirming that Butler was incapable of processing the results.

I have instead altered the API call to do the processing and return the results in a formatted single entry.

ie. Return all the movies seperated by \n in a single JSON field allowing 

{httpresponse.relatedMovies[0].title}

to include all the results. 

@Steve Nyveld 

How are planning to  iterate through each of the values? Or you just need to see them as separate items on a card description?

@Steve Nyveld 

You will not be able work easily with a list in Butler unless you have them as a checklist or attachments (see actions in Cascade). 
Instead get an endpoint that can update the cards for you instead. You can use http to trigger the update giving it the card id. 

0 votes
Iain Dooley Community Leader Aug 03, 2021

@Steve Nyveld there's no looping in New Butler, but for this code approach you may be interested in our BenkoBot platform:

http://www.benkobot.com/

You can see some examples and a "crash course" here:

https://trello.com/b/IoHmhz5c/benkobot-community-board

The crash course tells you how to make calls out to any external API using the ___request object

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,303 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