# Save multiple responses to different variables

**URL:** <https://community.postman.com/t/save-multiple-responses-to-different-variables/17868>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [November 19, 2020, 12:03pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868 "2020-11-19T12:03:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gabriel](https://community.postman.com/u/gabriel)\
**Post date:** [November 19, 2020, 12:03pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/1 "2020-11-19T12:03:22Z")

</div>

Hi all, hope you as well.

My question is, I need to save a value from a response in a variable (this step is ok), but the problem is, we are using here a CSV input for this request on the collection runner.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/4/f417793ff2cffc32b649fdc5711d9a6b26e46246.png)

When I do that I have a lot of responses (one for each line in the CSV input) using a single request.

Which type of “Test” do I need to use to create a variable for each response for the CSV line entry? the way we know here we create an environment variable with a specific name, but if I run the inputs all the values I need in the response will go to this same variable and will replace the last value.

This is how we save the value in a variable here:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/e/9eec26ddc2ab6cab55e71450f26d56902c2d0eb4.png)

Is it possible to put a counter in the variable name or something like that to have different names for each CSV entry and save all the responses?

Thanks a lot,

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 19, 2020, 12:18pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/2 "2020-11-19T12:18:02Z")

</div>

Hey @gabriel

You could have something simple that using the `pm.info.iteration` function to add the current iteration to the variable name? I’ve added a `+1` as the number is zero indexed.

```auto
pm.environment.set(`response-${pm.info.iteration + 1}`, JSON.stringify(pm.response.json()))

```

---

<div class="post-metadata">

**Author:** ![gabriel](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gabriel](https://community.postman.com/u/gabriel)\
**Post date:** [November 19, 2020, 1:15pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/3 "2020-11-19T13:15:27Z")

</div>

Thank you so much, it worked!

Just one more doubt is it possible to save just a specific value from the response in that way? Just to be faster.

Thanks,  
Gabriel

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 19, 2020, 1:17pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/4 "2020-11-19T13:17:35Z")

</div>

You can save whatever you like 😃

That was just a generic solution as I don’t know the full context and response structure of your API. 😃

---

<div class="post-metadata">

**Author:** ![gabriel](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gabriel](https://community.postman.com/u/gabriel)\
**Post date:** [November 19, 2020, 4:21pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/5 "2020-11-19T16:21:44Z")

</div>

Thank you so much Danny. You helped me alot

---

<div class="post-metadata">

**Author:** ![BonnieThorne](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@BonnieThorne](https://community.postman.com/u/BonnieThorne)\
**Post date:** [April 16, 2021, 9:39pm UTC](https://community.postman.com/t/save-multiple-responses-to-different-variables/17868/6 "2021-04-16T21:39:02Z")

</div>

This has been extremely helpful so thank you, however, I have a new problem. I have saved values in this way, in my case I have 48 ids set in the environment as id1-id48. In a separate collection I want to grab these ids in order 1-48 and place them in 48 get requests to test the json schema of the async responses. I have my other values for the request stored in a csv which I use to run my collection. How would I go about doing this?
