Persist environment variable automatically after updating it's value

Hello all!

I have an environment variable as a mock response and every time I update the environment variable value, I need to persist it to be able to reflect it as a response form the mock server.

Is there some way I can automate this (persist process) so that I can run all my requests at a time in the collection runner.

Thanks in advance for your replies!

Hi bbahadur,

Welcome to postman community :slight_smile: .
I believe what you are looking for is to set the environment variable automatically rather than manually?

If that is the case you can use

pm.environment.set("<key>",<value>)

Let me know if this helps.

Regards,
Skandh

Hey @skandh-15 ,

Thanks for your response,
I am able to set the environment variable value, what I want to do is to persist the variable value, i.e. have both ‘initial’ and ‘current’ value updated. And I want to do this via code/script, rather than clicking on the ‘persist all’ button. I hope I made the scenario more clear.

BR,
Bharat.

I somehow missed this in the help center. The problem is now solved.
Sending the PUT request with the details of the same environment every time I update the Environment variable’s value. Working well.