In this blog post, we'll discuss how to effectively use iterators and array aggregators in Make to iterate over multiple items independently.
When working with APIs and other data sources, you often need to process various sets of data independently. For example, you might need to handle business unit levels, agreement types, and user details separately. Using iterators and array aggregators in Make, you can achieve this efficiently, the key is in ensuring you aggregate on the right module.
Step 1: Fetch Users from Page 1
We will start by setting up the test calls to get some data to iterate over.
Start by making a GET request to the API to fetch the list of users from the first page.
HTTP Module
Action: Make a request
Method: GET
Parse Response: True
Step 2: Iterate Over Users from Page 1
Use an iterator to process each user from the first page individually.
Iterator Module
Array: The list of users from the HTTP module
Step 3: Fetch Detailed Information for Each User from Page 1
For each user obtained from the iterator, make a GET request to fetch detailed information.
HTTP Module
Action: Make a request
Method: GET
Parse Response: True
Step 4: Aggregate User Data from Page 1
Aggregate the detailed user information obtained from the previous step.
Array Aggregator Module
Feeder: The output of the Iterator module
When you have selected the right iterator module you will notice a grey shading around the grouped activities.
Step 5: Fetch Users from Page 2
Make another GET request to the ReqRes API to fetch the list of users from the second page.
HTTP Module
Action: Make a request
Method: GET
Parse Response: True
Step 6: Iterate Over Users from Page 2
Use another iterator to process each user from the second page individually.
Iterator Module
Array: The list of users from the HTTP module
Step 7: Fetch Detailed Information for Each User from Page 2
For each user obtained from the iterator, make a GET request to fetch detailed information.
HTTP Module
Action: Make a request
Method: GET
Parse Response: True
Step 8: Aggregate User Data from Page 2
Aggregate the detailed user information obtained from the previous step.
Array Aggregator Module
Feeder: The output of the Iterator module
If we then run the full scenario you can see that each id query has repeated 6 times while the call for the next page ran only once as expected:
Why Use Iterators and Array Aggregators?
Iterators and array aggregators are powerful tools in Make that allow you to handle complex data workflows. By using these modules, you can:
Process Data Independently: Handle each piece of data independently without affecting the overall scenario run.
Fetch Child Items: Easily fetch child items for an entity from different endpoints.
Aggregate Data: Combine processed data into a single array for further actions.
By using iterators and array aggregators in Make, you can efficiently process and handle multiple API responses independently. This approach simplifies the integration process and ensures that data from different sources is processed in a structured manner. Whether you're creating records, updating entries, or performing other actions, iterators and array aggregators are powerful tools that can streamline your workflow.