Set environment current variable values to initial values

Hi all,

I have a set of environments in Postman and each environments contains hundreds of variable values (saved on current values) that I used in testing. Upon exporting or duplicating the environments, the values are removed.

Is there a quick process of transferring/bulk moving the variable values from current values to initial values ?

Would really appreciate any suggestions.
Thank you.

This question has been asked before, and I’m pretty sure the answer was “no”. There is no quick way (but I guess this is down to your definition of “quick”).

If I remember rightly, the solution was to use the Postman Collection API to update the info.

@danny-dainton Wasn’t this your solution? Do you have more details?

@andrea-ree. @michaelderekjones is right.

The neatest way to do this is to use the Postman API to update your environment object using the “Update an Environment” endpoint on the Postman API.

I’m not sure how that would work as if those values are only in the Current Value, the Postman API wouldn’t be able to see them. Much the same way as they are not part of the export file, those values are only ever local to you doing that session.

I guess you could get them all with pm.environment.toObject() and then grab the values. Then use the Postman API to update the environment with the data from the current values:

let environmentObject = pm.environment.toObject();

console.log(Object.values(environmentObject));

I would ensure that you trial this out against a dummy environment first to know that it’s working as expected before moving the you actual environment.


If you wanted to move them the Initial Value, you could just do that in the UI using the Persist All option, this will set the Initial Value to whatever the you have in the Current Value. That also sync’s those variable and doesn’t only keep them local.

Doing that, isn’t something that you can easily undo though and you would need to manually remove the Initial Values if you didn’t want them there.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.