Skip to main content

I have a Zap, which contains a loop that calls a sub-zap on each iteration. 

 

The sub-zap contains an API call that returns some results along with a ´nextCursorMark´ variable. In order to loop through all my results, I need to make the subsequent API call, updating the CursorMark to that returned by the previous API call; for this, I tried to use storage by Zapier in my parent Zap, setting the variable “cursor” to “*” for my first iteration, and updating it to the returned value from my sub-zap on subsequent iterations.

´Parent` zap

parent zap calls sub-zap using the variable from storage by zapier

On this step, I need to select the variable, which I set to the output of step n4 since I cannot use a further step to set the value...so I guess it´s just setting it to that static value on each iteration

trying to replace the variable for the next iteration with the returned value from the sub-zap

I´m not sure how I can replace the variable for the next iteration, since that value comes from a future step...

cursorMark is an entry in the sub-zap
cursor mark is used to iterate through the results from the API

 

 

sending the next cursor mark to the parent zap (returned from the API call)

 

Since my variable is not being updated but instead, my parent zap is always sending the variable as * to the sub-zap, which, instead of leaving me with all the results, just repeats a series of them.

 

How would you approach this? Is this the correct use of storage by Zapier? Is there an error in another part of the automation?

 

Thanks in advance!

Hi ​@Vir Villalobos 👋

Hmm, it looks like the Sub-Zap is always be sent the same cursorMark value every time as it’s taking the value from step 4.

From the screenshot it appears that the main Zap is using numbers to generate the loop, could these numbers be used to create the values for the cursorMark? If so I’d suggest having the cursorMark values set by the number of the loop iteration:

bc026e2bc7f16a76db437809e1d659da.png

That would ensure that for each loop iteration the Sub-Zap receives a different number in that cursorMark field. See Loop your Zap actions for more details on using loops. I’d also recommend removing the extra fields as they can sometimes causes errors.

Can you give that a try and let us know if that helps to get the Zap sending a different value for each loop iteration that is run?

Please note: when testing in the Zap editor a loop will only ever send the data from the first loop, not all loop iterations. So you’d need to turn on the Zap to test how it runs for all the loop iterations.

Looking forward to hearing from you! 


Hi ​@SamB! Thanks a lot for your reply.

 

I can’t set that value when I create the loop because the value is returned on each API call. The cursor mark is a parameter my API is returning on each call so I can loop through all the answers. 

So, I need to have that value changed on each loop, and set to a value I can only get when I work through the loop 🤔


Does this help clarify the issue?
 

Thank you again


I’m so sorry for missing your reply here previously ​@Vir Villalobos

I can’t set that value when I create the loop because the value is returned on each API call. The cursor mark is a parameter my API is returning on each call so I can loop through all the answers. 

So, I need to have that value changed on each loop, and set to a value I can only get when I work through the loop 🤔

Hmm, are these cursorMarks just a way of getting the next set of paginated results from an API call?

If so, could you potentially make a call to the API to get the total number of pages before the loop runs. Then use a Code step to generate a list of each page number. For example if there were 9 pages of results it would output 1,2,3,4,5,6,7,8,9. Then in the Loop you’d select that list from the Code step, then you could pass that value to the Sub-Zap so that the CursorMark is dynamically updated on each loop run without needing to bother with a storage step. Or if they aren’t numbers but are instead unique IDs for the items you want to reference for each call, is it possible to make a call that would obtain a list of all the desired cursorMark values before running the loop? That way the list of the different cursorMark values could be passed to the loop so that a call can be made for each one individually.

Would that sort of approach work?


Reply