According to the docs, they say that Architect Loop blocks expect a standard JSON array format, but the error message Index 5 is out of bounds for array length 5 often points to a parsing issue rather than a true index error.
I hit this exact 401-style logic error when my Data Action returned malformed JSON. Look closely at your sample data: ["id": "1", ...]. Those square brackets [] around key-value pairs create an invalid JSON structure. Standard JSON objects use curly braces {}. If the parser fails on the first element, the resulting array might be empty or contain nulls, causing the loop to crash when it tries to access index 5 on a broken structure.
Ensure your Data Action returns valid JSON like this:
[
{"id": "1", "val": "A"},
{"id": "2", "val": "B"},
{"id": "3", "val": "C"},
{"id": "4", "val": "D"},
{"id": "5", "val": "E"}
]
Also, verify the content type header in your custom Data Action is set to application/json. If it defaults to text/plain, Architect might treat the response as a string instead of an array, leading to unexpected length calculations.
Since I am still debugging token refresh issues in my Python scripts, I tend to over-validate responses. Here is a quick curl test you can run to validate the payload before it hits Architect:
curl -X POST https://api.mypurecloud.com/api/v2/data-actions/custom/my-action \
-H "Authorization: Bearer {{your_token}}" \
-H "Content-Type: application/json" \
-d '{}' | jq .
If jq throws a parse error, your Data Action logic is the culprit. Fix the JSON syntax to use curly braces for objects, and the Loop block should iterate through all 5 items without throwing an out-of-bounds error.