# Chain array of ids from one request to other

**URL:** <https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634>\
**Category:** Help Hub\
**Created:** [September 30, 2022, 5:04am UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634 "2022-09-30T05:04:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![durgeksh](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@durgeksh](https://community.postman.com/u/durgeksh)\
**Post date:** [September 30, 2022, 5:04am UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/1 "2022-09-30T05:04:25Z")

</div>

I am working on an api testing. In first POST request, I am fetching some files from csv and running all the files and getting an associated runids. In next GET request, I want to iterate through all the ids and test their status on another end point. Then, there is one more GET request where I need to iterate through the runds and get another status.

I tried using single collection, but there requests are run one by one and not all iterations per request. I want to get all the iterations for first POST request and then all for remaining two GET requests individually.

Thank you!

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 30, 2022, 9:35am UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/2 "2022-09-30T09:35:55Z")

</div>

Have a look at the following post, which may achieve what you are attempting to do. The logic will be similar for doing what you need.

> [@Another data driven approach](https://community.postman.com/t/another-data-driven-approach/39609):
>
> I’ve seen a few posts now where the poster would like to run all of the requests in a collection\folder, but needs to run a particular request in the collection\folder x number of times using a data driven approach. Currently with Postman, the whole collection\folder will run once for each line in the CSV or JSON file. Typical use case would be where the tester wants to authenticate once and then run x number of tests after authentication. There might be two or three steps that need to happen…

However, I’m not quite following your logic here.

Sounds like you should get a single run ID at a time, which would then enable the two following GET requests to follow in order without you having to create loops in code. Can you format your CSV file so there is one runID on each line? So the test runner can handle the loop.

---

<div class="post-metadata">

**Author:** ![durgeksh](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@durgeksh](https://community.postman.com/u/durgeksh)\
**Post date:** [September 30, 2022, 10:17am UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/3 "2022-09-30T10:17:07Z")

</div>

Thanks. But, I want to chain environment variable from POST request to the two GET requests. Requirement is like this. All the files will be posted to POST end and get runids in return. These ids will be stored in an environment variable in the form of array. Then access these array elements one by one in two of the successive GET methods and get the status accordingly.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 30, 2022, 12:15pm UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/4 "2022-09-30T12:15:00Z")

</div>

You would have to use sendrequest() in a foreach loop like in the previous example post.

This would have to be in the Tests Tab of the initial POST request (so they run after the initial post). (They won’t be separate request).

---

<div class="post-metadata">

**Author:** ![durgeksh](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@durgeksh](https://community.postman.com/u/durgeksh)\
**Post date:** [September 30, 2022, 12:26pm UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/5 "2022-09-30T12:26:32Z")

</div>

thanks. but how shall I advance the iterator which I am using from csv file.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 30, 2022, 12:47pm UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/6 "2022-09-30T12:47:29Z")

</div>

Can you post an example (redacted) CSV file as I don’t quite get what you are trying to achieve.

You might need to use the Tests tab at a collection or folder level (so it runs after each request in the folder).

---

<div class="post-metadata">

**Author:** ![durgeksh](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@durgeksh](https://community.postman.com/u/durgeksh)\
**Post date:** [October 3, 2022, 5:43am UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/7 "2022-10-03T05:43:48Z")

</div>

Thanks. I am trying to run a csv file which contains name of a files to be posted through POST request. In return I get unique ids for each of the files. When, I get these ids, I have to check two statuses about them on two other GET requests.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 11, 2022, 4:15pm UTC](https://community.postman.com/t/chain-array-of-ids-from-one-request-to-other/39634/8 "2022-11-11T16:15:46Z")

</div>

@durgeksh

It’s a bit late now, but if you are still trying to achieve this, then the following topic has a solution of sorts.

[Post Looping through an Array not working - Help - Postman](https://community.postman.com/t/post-looping-through-an-array-not-working/40758/6)

It uses a pre-request script to retrieve your stored array.  
The pre-request script uses the JavaScript array.shift() function which returns the first element and also importantly deletes that first element from the array.  
You then write the first element to a new collection variable to use in the actual request, and also update the array variable stored which will now have one less entry.

In the tests tab of the actual request. You have a tiny bit of code that checks the length of the array and uses the Postman setNextRequest function to keep running the same request if the array is larger than zero. (The pre-request will keep triggering and will keep removing the first item in the array until there are no more entries).

Note: setNextRequest only works from the Postman runner.
