Passing sequence of requests from csv

Hi,

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.

Hey @maintenance-physici1,
Welcome to the community :wave:

Seems to me like there are certain conditions that could decide the sequence of requests. Have you tried building a workflow already?

1 Like

This requires a bit of scripting. I did a tutorial explaining how to do this a while back.

I hope this helps.

4 Likes

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?

You can’t have two files. The CVS is a much simpler format that does not allow for such complex data structures.

Look into putting your iteration data into the JSON file as well.

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

https://www.postman.com/praveendvd-public/workspace/postman-tricks-and-tips/overview

here you go ,

https://www.postman.com/praveendvd-public/workspace/postman-tricks-and-tips/collection/8296678-aaf0bd24-a70d-4404-871d-2dd332cac18b?ctx=documentation

read the instruction to know how to use it :slight_smile: here i am using postman API to get request list and runnning request using index

HI Guys,

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?