Architect Loop block iteration over Data Action JSON array

Looking for advice on handling the payload structure when feeding a Data Action response into an Architect Loop block. My REST call returns [ { "id": "123" }, { "id": "456" } ], but the Loop only executes once, iterating over the array object itself rather than its elements. I’ve tried setting the input to {{restResponse.body}} and {{restResponse.body[0]}} without success. What is the correct expression syntax to ensure the Loop iterates over each object in the JSON array returned by the Data Action?

This is typically caused by the Loop block expecting a specific JSON array structure, but often the REST response body is treated as a single object or string depending on how you parse it. In my experience debugging webhook payloads and data actions, the issue is usually that {{restResponse.body}} isn’t being interpreted as an iterable list by the loop engine.

Try forcing the conversion to an array using the array() function or ensuring the JSON path is explicit. Instead of just {{restResponse.body}}, use:

Or, if your response is nested, point directly to the array index:

Make sure your Data Action output is strictly a JSON array [], not an object {} containing the array. If the REST response is a string, you might need to parse it first, though Architect usually handles raw JSON automatically.

Warning: If the array is empty, the loop will skip entirely. Add a conditional check before the loop to handle empty results gracefully, otherwise your flow might hang or error out silently in the logs.

{{array(restResponse.body)}}

{{restResponse.body.results}}

This looks like a data type mismatch rather than a syntax error.

Cause:
The Loop block requires an explicit iterable object; if the REST response body is parsed as a string or single object, the engine treats it as a single item.

Solution:
Wrap the expression in array() to force iteration. Use {{array(restResponse.body)}} as the loop input to ensure the engine processes each element.

{{array(restResponse.body)}}

Check your REST action parsing. Error: Loop block iterates once.
The issue is often that the body is parsed as a string. Ensure “Parse as JSON” is true in the REST action. If it remains a string, array() won’t help. In Terraform genesyscloud_flow, verify the action config. If the payload is valid JSON, {{restResponse.body}} should iterate. If not, wrap it: {{array(restResponse.body)}}.

According to the docs, they say that {{restResponse.body}} is strictly a string type until explicitly parsed, which is why the Loop block treats the entire JSON string as a single iteration item. Wrapping it in array() does not parse the string; it just creates an array containing one string element. You need to ensure the REST action in Architect has Parse as JSON enabled. If that is already true and it still fails, the response might be wrapped in a root object like { "data": [...] }. In that case, you must reference the specific key: {{restResponse.body.data}}.

I usually lock these definitions in Pulumi to prevent drift. Here is how I configure the REST action to ensure the body is treated as a JSON array before it hits the Loop:

const restAction = new genesyscloud.flowActionRest("myRestAction", {
 flowId: flow.id,
 name: "Fetch Items",
 method: "GET",
 url: "{{vars.apiUrl}}",
 parseBodyAsJson: true, // Critical: ensures body is an object/array, not string
 timeout: 30000,
});

// Loop input should reference the parsed array directly
const loopAction = new genesyscloud.flowActionLoop("myLoop", {
 flowId: flow.id,
 name: "Process Items",
 loopInput: "{{restResponse.body}}", // Now iterates correctly
});

If parseBodyAsJson is false, Architect sees "[ { id: 1 } ]" as text. Always verify the Data Type in the flow builder to confirm it is an Array, not a String.