Run several requests with different number of data from csv on Postman

I have one .csv file with some data for my Postman like this:

Name,City
Jhon,New York
Lucy,London
Adam,
Alex,
Ron,

and I have one Collection with 2 reqs:

GetAge

{
    {{Name}}
}

GetInfoCity

{
    {{City}}
}

How can I run my Collection with a .csv file to run the first request req1 (GetAge) 5 times and then the second request req2 (GetInfoCity) 2 times, using a data for my .csv file dynamically?

Thanks.

Hey this is kind interesting thing what I will suggest add a flag in the csv file, when to skip request and on the basis of the you can skip current execution of request in pre-script. as if now i don’t think so there is such customization available for csv runner.
Hey MR. @danny-dainton, can you please confirm do we have such feature ?

3 Likes

As you will always have the name, you don’t need to do anything particular with the first request. You just let it run normally.

You can use the skipRequest() function to skip the City request if the data is missing from the CSV file.

For example..

let currentCity = pm.iterationData.get("City");

if (currentCity === undefined || currentCity === null || currentCity === '') {
    console.log(`${pm.info.requestName} : No City - skipping request`)
    pm.execution.skipRequest();

} else {
    pm.environment.set("City", currentCity);
    console.log(`${pm.info.requestName} : ${pm.environment.get("City")}`)
}
2 Likes