Workflow works once, processes 1000 records, then fails

Hi! I’ve been wracking my brain on this for the past week and no matter the tricks I try I can’t seem to figure out why this workflow only completes one loop.

Here’s my workflow. I’m on n8n cloud running version [email protected].

Here’s what it does in a nutshell (or what it is supposed to do):

  1. Create a custom variable in execution data called version_max = 0.
  2. Lightspeed’s API uses a resource specific cursor, a monotonically increasing integer called version. I have a little over 7k product records so the loop should execute 8 times (which it does), each loop changing the parameter after=x, where x is the version max returned by the last response. This is handy because later, if all I want are the updated products after an initial upsert, I can just start the workflow with the last version_max I saved into my Airtable.
  3. We save that version_max to $executions.customData for later retrieval.
  4. The HTTP request gets up to 1000 records and returns two JSON objects: data (which contains the products I want to upsert to my Airtable) and version (which has the range of versions that are contained within the data object.
  5. I save the version_max, then split out the data object from the 1000 records.
  6. Next I loop over the 1000 records and upsert them into my table.
  7. Once all of the 1000 records are upserted, the loop goes back to the HTTP request and is supposed to grab another 1000 records.

All of this works great up to #7. Now, I could just start the workflow and run it eight times and I’d get everything I currently have in my POS, but I’d like to be able to make this work on a nightly schedule and not have to execute it 8+ times. That just feels icky.

I also tried doing this by looping just the HTTP request, taking the 8 output runs, and combining them into one JSON. This just doesn’t work at all. I’ve seen some examples thrown around that look old/out of date, and they don’t work in n8n cloud, like the code combining multiple JSON outputs into a single JSON file. Doesn’t work.

Any ideas?

1 Like

I have a creative approach, not really sure if it would work

  1. Set the trigger node as " When executed by another workflow"
  2. create 8 different workflows and set their trigger node as " On schedule" and trigger the main node

Now you can schedule them at 5-10 mins interval at your convenient time

Let me know if it works! :grin:

I appreciate the reply. Sometimes it’s ok to hardcode something if you just need it for a one-off, but it wouldn’t be useful here. I ended up solving this last night with sub workflows in a loop. No need to run it a hard eight times since in a production it could be n pages.

1 Like

Creativity wins over everything
It would help the community if you can mark this topic as resolved @JoshWilhelmi :grin: