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

Butler HTTP requests - how to loop results in returned JSON

Steve Nyveld August 3, 2021

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
Steve Nyveld August 3, 2021

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. 

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.
August 3, 2021

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

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.
August 3, 2021

@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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 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
AUG Leaders

Atlassian Community Events