Course 1: Getting started with API AutoFlow
2 min read · 8 min video
Lesson 5: Master Iteration (loop) to Create Complex Solutions
Once you have a good understanding of loops, you can build a wide range of solutions.
The good news is that loops are relatively easy to understand. There are just a few things that you need to remember
- Loop iterates over a list (array)
- You apply actions to each item on the list
So, if you want to apply the same action to each item on the list, it helps to have all the items to be in the same format (a.k.a structured data).
Lesson Outline
- Apply
Interation
action to theflow
- Set the array to loop over
- Apply actions to the conditions
1. Apply Interation
action to the flow
From the right navigation, select the iteration category.
Drag and drop the filter iteration to the flow.
The filter iteration only passes value when true
. So, inside the iteration, we will need to put a boolean
condition to filter our result
.
Simulation data
To help with the solution building, let’s simulate an array with ["name", "gender"]
. We will create an iteration to filter just female
.
Click here to learn more about data simulation
2. Set the array to loop over
Drag and drop the request/body
that we just simulated to the iteration action.
Understanding output
To apply actions on items, it helps to reference the index
and the value
of the iterated items. The final output is the result
.
Note. The filter
iteration action only passed when the value is 1
(true).
So, as the iteration goes over each of the items, we need to make the value into 1
to add it in the final result
3. Apply action to the conditions
The condition can look for the word female
. There’s perfect action for that called string/contain.
String/contains action checks if the data contains a certain string and output 1
for true and 0
for false.
Drag-and-drop the string/contain action inside the iteration.
Again, the iteration checks the value
of each item from the array. In the right bottom pane, you have access to the value
.
Note: Only the first value from the array is shown for reference.
Drag-and-drop the value
to the action’s properties.
Next input the content that we want to filter. In our case, we are looking for items with the string "female"
.
Output needs to be value
since the iteration looks at the value for true or false.
Click on the small square outside the iteration. After the iteration is complete, it will output result
with the value 1
(true).
Below, we have filtered the items with string female
.
Download Master Iteration (loop) to Create Complex Solutions configuration
Learn how to use configurationNEXT » Lesson 6: Learn How to Work with Databases and APIs