Running API Workflows Sequentially

I’ve run into a situation where I need to run API workflows sequentially. I need to process a list of things in an API workflow and then initiate another API workflow after the last item has been processed. @alex5 came up with a clever approach:

a) Create a table called WFC (for workflow Control) with at least two fields: ListSize and ItemNumber.
b) Modify the workflow to accept a parameter (e.g. wfc) of type WFC
c) Add a step before scheduling the workflow to create a new thing (a WFC) setting ItemNumber to 0 and ListSize to the count of all the elements of the list that you will pass to the workflow when you invoke it (effectively running the same query twice, one now with a :count at its end and the second time when you invoke the workflow)
d) Schedule the workflow, passing the result of the previous step as the wfc parameter (or whatever you called it in step b).
e) As the first step in the workflow, increment the value of wfc’s ItemNumber by 1
f) When appropriate (I usually do it at the end of the workflow) put steps that are executed “only when” wfc’s ItemNumber" is wfc’s ListSize. This is what tells you that you are in the last element of the list.
g) you may want to cleanup WFC at this point of periodically because otherwise it will grow forever.

It would be nice if we were able to sequence API workflow runs. Anyone come across an alternative method?


The only way I found is triggering a Custom Event at the end of each run workflow. Like you do. And I add a condition on this Custom Event, so it run only if all the workflow on the list have already been done.

For exemple, this what I do when I need to run an API on a a list of Products.

API Endpoint - Workflow Control + List of Products

  1. Modify Workflow_control’s Date = current date/time
  2. Schedule API endpoint on a list of Products

API Endpoint - Product (+ you also need to send the WorkflowControl object)

  1. Set the actions you need
  2. Then at the end of the workflow, Modify Product’s Workflow_date = current date/time
  3. Run the custom event (WorkflowControl type)

Custom Event - ONLY WHEN all the Products’s workflow_date > Workflow_control’s Date
Set the actions here you want to run only when all the Products have been updated

@emmanuel Why couldn’t we trigger a last API enpoint AFTER all the workflows on a list have finished ?


This topic was automatically closed after 70 days. New replies are no longer allowed.