Store response values as variables from each iteration

I’m running my postman collection with 4 iterations which have 3 requests.
With each iteration, It gives me a new order ID, transaction ID etc.
I want to store them all and use them in the next request or next collection.
but right now I’m able to save data only from the last iteration.
I can see the last iteration’s data in my environment variable but not the first three.
i want the first three iteration data also.

Hi @security-pilot-41358. Welcome to the Postman Community.

It looks like you’re using the same key for all the variables stored in each iteration. This means the value will be overwritten by the new iteration value each time that iteration runs.

You can consider storing each iteration key with an iteration index. So instead of “key”, it is “key{N}” where N is an integer(1, 2, 3, 4, etc)

Can you provide an example response to see what we are working with?

Can you provide an example of what you want the final environment variable to look like?

Logically, you will need to start with a blank array. Either a collection or environment variable. (Environment if you want to use it across collections).

On each iteration you will first need to retrieve the array, then extract the relevant details in the response to an object and push that object to the array and finally re-save the collection\environment array.