I have an array of 10K user_id. I need to send them in Request Body using Collection Runner. I need to send 100 user_ids in one request and I will loop through the request 100 times using Collection Runner.
So that is how they need to be referenced in the body.
{{currentId1}} not {{currentId[0]}
You do have an array called currentId, but you can’t reference them in the body using the handlebars (curly brackets) due to scope. The array is a local variable which will only be available to the pre-request script. It won’t be available to the body so they will be returned as “undefined”. (You can’t reference local or global variables in the body via its handlebars).
I also recommend you call the variable something else, so its clear on what is what.
Another option here is to have place holders in the body for these ID’s, and then directly overwrite them using the following method. This way the body will have the actual value and you are not replying on variable per se at this point.
const body = JSON.parse(pm.request.body.raw); // retrieve current body
// update the elements using your loop
// you should be able to target the element using the array index
// using the same index number that you are looping through your test data
pm.request.body.raw = body; // write back updated body