Do we have to use "Initial" variables from environment variables

I am running a collection from Newman using environment variables stored with Postman and trying to update the variables in the tests, after one of the requests, but it does not update the initial value and the value used in the next collection run is retrieved from the **initial values". Is that the proper behavior or am I doing something wrong?

Hey @ConstantinMalii

Welcome to the Postman community! :trophy:

Would you be able to provide some information about your Newman run please? More specifically, how are you accessing the Collection and Environment files.

For all variables, the initial value is the one that’s syncd to the Postman servers and can be seen by you and your team members.

The current value is only seen by you and is not syncd to the Postman servers.

If you had variables only as the current value, this wouldn’t be part of any exported file so Newman wouldn’t be able to pick that up and use it for the run.

It would be interesting to see your set up and how you’re running the collections before I go into more detail though :grin:

Hey @dannydainton

Thanks for checking this out!

I have setup Newman using the JS package and the collection and env var are retrived by their GUID.
    collection: `${constants.MCC_COLLECTION_GUID}?apikey=${apiKey}`,
    folder: requests,
    iterationData: constants.ITERATION_DATA_FILE_NAME,
    bail: true,
    insecure: true,
    reporters: ["cli"],
    environment: `${constants.MCC_ENVIRONMENT_GUID}?apikey=${apiKey}`,

we run this script from bash or powershell command line.

The env vars are being updated in the Tests part of the request like so:


All these variables have default values so that they are exported, but I can see the value being updated only for current, but not initial.

Side note - this is separate collection runs. First collection run should update the vars and the next collection run should use those values.

As you’re grabbing that from the Postman API - That would only know about the value set in initial, as the current value doesn’t get pushed to the Postman server.

I created a reporter that might give you a few about the variables used during the run

I’ve included a flag that displays the environment variables on the report.

Not sure it’s going to give you the full answer but might highlight what’s happening maybe :grin:

oh, i see. so those vars are not being tracked in any way. that would make sense.

is there another way load those env vars so that they are tracked?

It depends what you mean by ‘tracked’ :grin:

You can load environment vars, that are separate to the environment URL, in the Newman object like this:

envVar​: ​[​ 
        ​{​ ​"key"​:​"var_name_1"​,​ ​"value"​:​"var_value_1"​ ​}​,​
        ​{​ ​"key"​:​"another_secret"​,​ ​"value"​:​`​${​process​.​env​.​ANOTHER_SECRET​}​`​}​

That would also allow you to use system level environment variables that you want to keep hidden, like a Password or an API Key.