Save multiple responses to different variables

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.


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:

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,

Hey @gabriel

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

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

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.


1 Like

You can save whatever you like :smiley:

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

1 Like

Thank you so much Danny. You helped me alot

1 Like