I have 10 api requests in a collection in postman. For case A I need 5 of thise in sequence. For case B I need four of those in another sequence. For case C I need 3 of those in another sequence. Like wise I have 53 cases. My question is how can I pass the sequence of api’s to run for case A,B,C etc from a CSV file since it is all in one collection.
Thanks vdespa, this is exactly what I wanted to describe. However, I have one problem i.e. I am already passing my data from a CSV file since I have variablized all values in the request body which is mapped to the CSV file columns. so how to pass the routes json? Can we pass 2 data sheets?
To follow what @vdespa does you can store route as an environment variable and access it as
route = JSON.parse(pm.environment.get("route"))
you can also access the full requests in collection using postman collection api and use some condition i will try to create a public collection for you to try out
Apologies for the late reply, I modified the code from vdespa to pickup data from CSVfile as a string and then convert it to an array with something like this:
postman.setNextRequest(getNextRequest());
function getNextRequest() {
let routes;
if (Array.isArray(pm.globals.get("remainingRoutes")) && pm.globals.get("remainingRoutes").length > 0) {
routes = pm.globals.get("remainingRoutes");
} else {
var strwithout = pm.iterationData.get("API_Sequence");
if (strwithout === undefined){
console.log("The result for strWithout is undefined");
} else {
routes = strwithout.split(" "); //To convert the api_sequence string into array
}
}
const nextRequest = routes.shift();
pm.globals.set("remainingRoutes", routes);
if (nextRequest === undefined) {
pm.globals.clear("remainingRoutes");
console.log("Check WHether CLEARING GLOBAL");
return null;
}
return nextRequest;
}
However, what i am seeing is that the if (nextRequest === undefined) is not getting triggered and it doesnt clear the global variable, as a result it executes the api’s in a different manner. Also after executing api 1,2,3 it again attempts toe xecute 2,3 which it shouldnt do. Any ideas what i am doing wrong here?