Using a loop block to gather all results from a REST API

Hi Team,

Have a possible simple one but my technical knowledge with JS isn't advance enough to figure it out.

I have a rest API that allows me to grab 100 records at a time, if there are still records after it, it returns a response code of 206, if there are not further records, it returns 200. See below as per api documentation:

In my head, it should be possible to make this API call and have a JSON object in the range value field that the loop goes through and updates based on 206 or 200 response then returning the accumulated results.

I'm not sure if this has to happen in the way of First API call -> Loop block repeating the api call
Just in the one loop block using the code option instead (but then unsure what to reference the loop block too).

Would greatly appreciate any help in this idea. I have tried getting through it with chatgpt but my coding knowledge isn't quite enough to get it over the line.

See below for an excerpt of what the format of the returned API call.


Hey @tomrezoando,

I think the way the API is structured requires you to make an initial API call to determine whether or not you need to make successive calls. The first query would go into a branch that checks for the status code and when == 206, can be sent along to a code based loop which would be able to determine how many new queries need to be made to gather and return all of the results.

Here's a little example of a theoretical type of workflow to use -- I am uncertain of the actual response header locations so I made some assumptions in the code block:

There's probably more efficient ways of making the looped queries, but this is more of a proof of concept that I think you are looking for. In this example, you'd still have to join in the data from the results of the initial query (which would return either 100 items + the Content-Range header or just give you all of the items available if there were less than 100, but that is something which can be explored via the Else/Else-If functions branch node as well).

Hope this helps. If you have other questions or I misunderstood your intent, let me know!

1 Like