Getting a complete environment data


During an API execution I want to retrieve all the variables defined in the environment file.

pm.environment.get() will get me the value for only one variable, is there any other function which can fetch me all variables with there values?


Not sure what your trying to accomplish, but pm.environment.toObject() will return all the environment variables in an object. pm.globals.toObject() will do the same with all the global variables.

var zzz = pm.environment.toObject();
for (var key in zzz) {
    console.log(key + ' ' + zzz[key]);

Run the above and then open the postman console you will see an “object” which contains all the environment variable and then the loop will display, individually, each variable and it’s value.

Thanks dhoyt, this is exactly what I’m looking for.