Multiple dynamic REST API queries - best practice

I need to retrieve JSON results from different endpoints based on a date range e.g.
only the date part of the URL will vary.

https://my_s3_endpoint/2021/03/14/myfile.json
https://my_s3_endpoint/2021/03/15/myfile.json
https://my_s3_endpoint/2021/03/16/myfile.json
https://my_s3_endpoint/2021/03/17/myfile.json

I understand how I can define the endpoint resource and use that as a resource query.

I plan to select a date range via a DateRangePicker and then utilize that date range to dynamically define the date part of each resource query URL and call all of those endpoints via Promise.all() to retrieve all the data within that date range.

What is the best approach to accomplish this task?

I know I can create a Javascript query to execute each call to the dynamically created endpoints via a Promise.all() and then aggregate the returned results but is there an easier way already available in Retool to accomplish this same functionality without having to write custom code?

Hey @pjc714! You’re correct, looping through your endpoints via JS is the right way to go. You could create one query that hits the endpoint with that dynamic date piece, and then trigger is repeatedly from a Run JS Code query like:

query1.trigger({
  additionalScope: {
    date: {{ datepicker.value }} 
  }
})

More on scripting Retool here: https://docs.retool.com/docs/scripting-retool#example-firing-an-api-request-for-each-row-in-a-csv

Thanks Justin I figured that was the only way to do it :smiley: :+1:

1 Like