Bit of help please with a repeat when using an api

Hi guys,

So I have an api which returns a number of pages (page: 1) in a query as well as data.
I have the repeat for the products and inserts working well, but I want to somehow repeat the whole thing so when it finishes page one the it will start again and add www.url/api?page=2 and so on until it gets to the last page (for example 38)
What would be the best way to do this. Here is my action upto now

Any ideas or help would be appreciated.

So, you want to repeat the API call?

Put a Repeat step right before ā€œAPI Action: apiā€, and place everything under it. You need a variable to keep track of the current repeat (maybe the Repeat itself has one? Maybe called index or something). In the API call you insert the counter variable (?page={{counter}})

Or, a less error-prone solution (especially as you donā€™t need to worry about variables colliding or whatever), at the end put a Redirect step to redirect to the current URL with a ?page=$_GET[ā€˜pageā€™]+1
(and in the API Call, you get the $_GET[ā€˜pageā€™])

Would that work?

I had a bit of trouble to understand your context, so donā€™t be afraid to ask if something in my question doesnā€™t make sense :slight_smile:

I would recommend following flow if you know how many pages:

  1. Find the numer of pages needed.
  2. Set a repeat to run that many time - just setting the values, say 38, will run it 38 times.
  3. Inside repeat, run API with ($index + 1) in URL for page number.

If you donā€™t know how many pages:

  1. Set a flag variable which says something stop = 0.
  2. Set a counter variable and set it to 1 (if needed).
  3. Use a while step with condition stop != 1.
  4. Inside while, set your URL with counter.
  5. Process the API results & check if another page needs to be processed.
  6. If yes, increase counter.
  7. In no, set stop = 1.

Hope this makes sense.

1 Like