Modify Iteration value while looping over csv for single API in collection

Team -
Requirement:
Collection:-
Post1(Login) → Post2(some task) → Post3(logout)
Here Post2 is some task which is supposed to loop over external csv data file.

I am able to run Collection wherein every API call is made for total count of iterations. What I require is just one Login and one Login. Iterations(based on iterationCount) should only happen for Post2 API call.

After researching on web, I found that setNextRequest is a way to achieve this. However, with js code in Pre-Request script section, I am able to create sequence like Post1 → Post2 → Post2 → Post2 and so on
However, every post2 request takes same Iteration=0 value from CSV i.e. iteration count value is not changing.

Please help.
CSV Data:
name,subnet,subnet-mask
Net_10.43.0.0-16,10.43.0.0,255.255.0.0
Net_10.47.0.0-16,10.47.0.0,255.255.0.0
Net_10.49.0.0-16,10.49.0.0,255.255.0.0
Net_134.37.164.0-23,134.37.164.0,255.255.254.0
Net_134.37.94.0-23,134.37.94.0,255.255.254.0
CAR_OCP_HFM_10.132.7.0m26,10.132.7.0,255.255.255.192
CAR_OCP_INTERNAL_10.132.6.0m24,10.132.6.0,255.255.255.0
CAR_OCP_INT_BE_FOR_DMZ_10.132.4.128m25,10.132.4.128,255.255.255.128
CAR_OCP_TESTDEV_10.132.4.0m25,10.132.4.0,255.255.255.128
INMMA1-134.37.74.0-23,14.37.74.0,255.255.254.0


Post2(in above description) is referred to Add-network-Bulk API call.

@arlem and @ronak
Need your inputs on this. Please guide further

Hey @spacecraft-speciali3 , my guess here is that since you start using postman.setNextRequest(), you’re going out of the normal collection runner flow and therefore never move on to the next iteration.

My recommendation would be to:

  • convert your CSV to JSON
  • save it as a collection variable
  • loop through it directly in the pre-request script instead of using the collection runner

Here’s an example where we have an array saved as a collection variable and we go through each item one by one:
https://www.postman.com/postman/workspace/postman-answers/request/9215231-d962e591-c679-4014-ab86-b38b2f8ebf69