Populating dynamic collections inside a JSON body
You almost always know the shape of the body you need to send. The endpoint is documented, the fields are fixed, you can write the whole thing out by hand.
What you don't know at design time is what goes inside the array.
{
"source": "zenphi",
"users": [ ... ? ... ]
}
Today that array holds three users. Next Tuesday it holds forty. On a quiet run it holds none. The rest of the body never changes — just that one part, and it changes on every single run.
That's the gap. Everything around the collection is static and easy. The collection itself is dynamic, and there's no field in the designer where you can type "however many rows come back".
Why you can't always route around it
The usual instinct is to send one request per item and move on. Sometimes that's fine.
Often it isn't, and not only because of speed:
Some endpoints simply don't accept one item at a time. Salesforce's composite tree, SendGrid's personalizations, most bulk and batch endpoints — they're built to take the whole set in a single body. Sending them one by one isn't slower, it's impossible.
Rate limits. Forty rows becomes forty calls, and you're throttled before you finish.
Partial failure. Item seventeen fails and you're left half imported, with no clean way to know where you stopped or how to resume.
Nothing to check. Forty responses to correlate instead of one to read.
And the array isn't always the whole point of the body, either. Often it sits next to static fields you also need to send — a sender address, a subject, a source system, an account id. So "just build an array" doesn't finish the job. You need the array populated in place, inside the real body.
The pattern
Put a placeholder where the list goes. In a Set Variable before your loop, write the complete body and mark the dynamic part with double curly braces, named after the key it fills:
{
"source": "zenphi",
"users": {{users}}
}
Fill it inside the loop. An Execute Script inside your For Each takes three inputs: the variable, the placeholder {{users}}, and the single item you want to add, built from the current iteration's tokens. The last action in the loop writes the script's bodyJson output back into the same variable.
Send it once. After the loop, point the Request Body of Make HTTP Request at the variable. It's already a complete JSON string, so there's no conversion step.
After three iterations, the variable holds this — static fields untouched, array populated:
{
"source": "zenphi",
"users": [
{ "email": "ann@company.com" },
{ "email": "bob@company.com" },
{ "email": "carol@company.com" }
]
}
Three items, or three hundred, or zero. The flow doesn't change.
There's a mini flow for this
You don't have to build any of it. The Dynamic Collection Body Builder mini flow is ready to download and import, with the script already written and every action wired up.
What you get with it:
Any body shape. Nested placeholders work too, so {"data":{"attributes":{"lines":{{lines}}}}} is fine. Static fields and static arrays are left exactly as you wrote them.
More than one dynamic list in the same body. Give each list its own placeholder and run one For Each per list. They share the same variable and each item lands in its own array. The loops can run in either order.
Any collection source. Sheet rows, table records, users, invoice lines, API results — if you can loop it, you can build a body from it.
It tells you when something's wrong. Invalid JSON, an item that isn't an object, a placeholder that doesn't match anything — the script returns an error and leaves the body untouched rather than sending a broken payload. The matchedBy and itemCount outputs let you watch the array grow in the run log while you're testing.
Empty runs are fine. No items means the array stays empty and the body is still valid.
Grab it here: Dynamic Collection Body Builder in the Mini Flows section. Import it, swap the sample body for your own, point the For Each at your collection, and you're done.