# Passing sequence of requests from csv

**URL:** <https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444>\
**Category:** Help Hub\
**Created:** [April 9, 2021, 10:03am UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444 "2021-04-09T10:03:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![maintenance-physici1](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@maintenance-physici1](https://community.postman.com/u/maintenance-physici1)\
**Post date:** [April 9, 2021, 10:03am UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/1 "2021-04-09T10:03:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![meenakshi.dhanani](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/meenakshi.dhanani/32/5980_2.png) [@meenakshi.dhanani](https://community.postman.com/u/meenakshi.dhanani)\
**Post date:** [April 9, 2021, 12:28pm UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/2 "2021-04-09T12:28:40Z")

</div>

Hey @maintenance-physici1,  
Welcome to the community 👋

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

> **[Building request workflows](https://learning.postman.com/docs/running-collections/building-workflows/)**

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [April 9, 2021, 5:22pm UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/3 "2021-04-09T17:22:34Z")

</div>

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

[![](https://img.youtube.com/vi/FWYKOR0Zj28/maxresdefault.jpg "Advanced workflows (request chaining) with Postman") ](https://www.youtube.com/watch?v=FWYKOR0Zj28)

I hope this helps.

---

<div class="post-metadata">

**Author:** ![maintenance-physici1](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@maintenance-physici1](https://community.postman.com/u/maintenance-physici1)\
**Post date:** [April 10, 2021, 10:45am UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/4 "2021-04-10T10:45:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [April 10, 2021, 12:22pm UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/5 "2021-04-10T12:22:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [April 10, 2021, 8:25pm UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/6 "2021-04-10T20:25:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [April 10, 2021, 9:08pm UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/7 "2021-04-10T21:08:20Z")

</div>

[https://www.postman.com/praveendvd-public/workspace/postman-tricks-and-tips/overview](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](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 🙂 here i am using postman API to get request list and runnning request using index

---

<div class="post-metadata">

**Author:** ![maintenance-physici1](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@maintenance-physici1](https://community.postman.com/u/maintenance-physici1)\
**Post date:** [May 10, 2021, 6:31am UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/8 "2021-05-10T06:31:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![maintenance-physici1](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@maintenance-physici1](https://community.postman.com/u/maintenance-physici1)\
**Post date:** [June 7, 2021, 6:07am UTC](https://community.postman.com/t/passing-sequence-of-requests-from-csv/22444/9 "2021-06-07T06:07:47Z")

</div>

I found the solution. Basically tweaked vdespa’s code to work with CSV. Thanks guys.
