AlexCode
AlexCode

Reputation: 4123

Postman get the environment name as a variable

I would like to know if it's possible to get the environment name as an environment variable in Postman.

Currently I'm setting it myself manually in the environment variables for each environment but it that can be retrieved from some sort of application variable that would be great.

I can't find anything in the docs.

Upvotes: 9

Views: 5390

Answers (2)

HalfBloodPrince
HalfBloodPrince

Reputation: 121

You can use following code snippet. This code will return you the environment name which is currently being used by POSTMAN.

console.info(pm.environment.name);
pm.environment.set("currentEnvName",pm.environment.name);
var environementName = pm.environment.get("currentEnvName");
console.log("Environement Name Current Used Is : "+environementName);

Upvotes: 2

Danny Dainton
Danny Dainton

Reputation: 25881

This should give you the name of the environment that's currently selected:

pm.environment.set("envName", pm.environment.name)

Postman

Upvotes: 5

Related Questions