I’m trying to process a list of users returned from a custom REST endpoint using the Loop data action in Architect. The initial REST call returns a valid JSON array of objects, but the Loop block seems to be treating the entire payload as a single item rather than iterating through each element.
Here is the response payload structure I’m receiving:
{
"users": [
{"id": "123", "name": "Alice"},
{"id": "456", "name": "Bob"}
]
}
In the Loop configuration, I’ve set the input to $.users and the iteration variable to current_user. Inside the loop body, I have a simple Assign block to log current_user.id. When I run the flow, the log shows the entire array object instead of the individual IDs. The loop count is set to 1, which suggests it’s not recognizing the array length.
I’ve verified the JSON path using the test console, and $.users resolves correctly to the array. Is there a specific data type requirement for the input variable in the Loop block? Or do I need to transform the response first? The documentation is a bit vague on handling nested arrays from external REST calls.
The problem isn’t the Loop action itself. It’s that you’re feeding it the whole JSON object instead of just the array slice. The Loop data action needs a flat list to iterate over, not a wrapper object with a property.
In your REST call’s response mapping, don’t just map the body to a variable. Map body.users specifically. If your response variable is restResponse, you want the loop to consume restResponse.users.
Here’s how I’d set that up in Architect. First, make sure your REST action saves the response to a variable, let’s call it userFetchResult.
Then, in the Loop Data action:
- Input Variable: Select
userFetchResult.users. This tells Architect to grab that specific array.
- Loop Variable Name: Set this to something like
currentUser. This is the temporary variable that holds each individual object during each pass.
- Loop Body: Now you can reference
currentUser.id and currentUser.name inside the loop.
If you try to pass userFetchResult directly, Architect sees one item: the object { "users": [...] }. That’s why it runs once. By drilling down to .users, you hand it the list [ {...}, {...} ], and it’ll spin through each entry.
Quick tip: if the REST call fails or returns null, the loop won’t run, which is good. But if it returns an empty array, it also skips. Just make sure your error handling covers the case where the API is down, because the loop will silently skip if the input is null or undefined.
You can also verify this in the debug logs. Check the variable inspector after the REST call. You should see userFetchResult.users as an array of length 2. If it shows as an object, your mapping is still off.
Let me know if that clears it up. Usually, this is just a mapping oversight.