Number range loops
Use Loop through number range to repeat steps for each number in a sequence. This lesson uses the quotes endpoint of The One API, a Lord of the Rings API, to paginate through results. The first request fetches page one and returns the total page count. Compare Numbers checks whether more than one page exists. If it does, the range loop fetches the remaining pages. If there is only one page, the Wrkflow goes straight to Done.
Watch the walkthrough, then use the template and key settings below as you follow along.
Copy the demonstrated Wrkflow
Click Copy template, open a Wrkflow in the Designer, and paste with Ctrl + V on Windows or Cmd + V on Mac.
Connect Start to the first Perform an API call and select your own The One API account connection on both API Wrk Actions before launching. Account credentials are not included.
Key settings
| Wrk Action | Setting |
|---|---|
| First Perform an API call | Use GET with https://the-one-api.dev/v2/quote?page=1. Add a numeric Custom Output named Pages using the response value $.pages. |
| Compare Numbers | Set the comparison to Pages > 1. Connect Yes to Loop through number range and No to Done. |
| Loop through number range | Set Starting index to 2, Ending index to Pages, and Loop increment to 1. Page one was already requested, so the loop starts at two. |
| Perform an API call inside the loop | Use GET with https://the-one-api.dev/v2/quote?page={{loopNumberRangeCurrentIndex}}. Insert Item index from the number range loop as the page value. |
| Continue loop | Map the range loop's Loop ID into Continue loop. Connect Continue back to the range loop and map Continue loop's Continue loop ID into the range loop's Continue loop ID setting. |
| Send to Launch Console | Inside the loop, log the current Item index. Connect Exit to a final Send to Launch Console with the message Done. |
The two ID mappings connect Continue loop to its matching range loop. Continue loop ID is optional when starting fresh, but configure the return mapping so the loop can advance through the remaining pages. See the Loops overview for how the pair works.
Check the result
Check both page-count cases:
- Multiple pages: keep the first request set to page one. Save and launch the Wrkflow. If the response reports three pages, expect
Page 2 requested,Page 3 requested, thenDone. For any page count greater than one, the loop requests pages2through Pages. - One page: expect Compare Numbers to follow No directly to Done, without running the range loop.
To create a one-page case, temporarily add an _id query parameter for one quote to the first request, such as https://the-one-api.dev/v2/quote?_id=<quote-id>. Replace <quote-id> with an ID from a quote response. Test the request and confirm it returns one result and pages: 1, then save and launch with that filter. Compare Numbers follows No directly to Done, and the range loop does not run. Restore the original page-one endpoint after the test.
Launch Console shows newer messages first; use timestamps to follow the execution order. This example requests pages and logs their numbers. The nested loops lesson adds processing for the items on every page.
Troubleshooting
- Page one is requested twice: confirm Starting index is
2. - The loop does not run for multiple pages: confirm Pages is a numeric Custom Output from
$.pages, the comparison is Pages > 1, and Yes connects to the range loop. - A page is missing or repeated: check the range loop's Ending index, Loop increment, and the API request's Item index value.
- The Wrkflow does not finish: check both ID mappings, the Continue return connection, and the Exit connection to Done. Confirm the comparison's No outcome also connects to Done.
Related resources
- Loops overview
- Loop through number range
- Previous: JSON array loops
- Next: Nested loops