Ok, lets start by making the event dates in the data file an array like following.
[
{
"id": "1",
"name": "first name",
"timezone": "US/Central",
"eventdates": [
{
"eventdate1": "2023-10-25"
}
]
},
{
"id": "2",
"name": "second name",
"timezone": "US/Central",
"eventdates": [
{
"eventdate1": "2023-11-10"
},
{
"eventdate2": "2023-11-11"
},
{
"eventdate3": "2023-11-12"
}
]
},
{
"id": "3",
"name": "third name",
"timezone": "US/Eastern",
"eventdates": [
{
"eventdate1": "2023-12-15"
}
]
}
]
You will want to retrieve this array in one of the earlier requests in the flow and then save it as a collection or environment variable. You can target the array through the special data variable that gives you access to the content of your data files.
pm.collectionVariables.set("eventdates", JSON.stringify(data.eventdates));
Remember to JSON.stringify when storing arrays and JSON.parse when retrieving.
In the pre-request script of the request you want to loop, you will then retrieve this array (using JSON.parse) and use an method available to arrays called shift();
What this does is retrieve the first element from the array, and also remove it from the array.
You will then save that element to the variable (eventdate) you want to use in the specific request, and you will also re-save the array (which will now have one less item).
let array = JSON.parse(pm.collectionVariables.get("testdates"));
let testdate = array.shift();
pm.collectionVariables.set("testdate",testdate);
pm.collectionVariables.set("testdates", JSON.stringify(array));
In the tests tab for the request, you will retrieve the array again as you need to check the length and will have an IF statement that keeps looping using setNextRequest while the array length is more than zero.
const response = pm.response.json();
let array = JSON.parse(pm.collectionVariables.get("testdates"));
let requestName = pm.info.requestName;
if (array.length > 0) {
postman.setNextRequest(requestName);
} else {
postman.setNextRequest(null);
}