Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman - Nested Environment Variables

Tags:

postman

I'm looking for a way to make environment variables in Postman, that contain other variables. For example: {Server}=localhost;{Port}=9200;{ServerUrl}={Server}:{Port}.

Like in Make...

This way it doesn't seem to work with Postman.

EDIT:

My attempt: enter image description here

like image 614
Moritz Rinow Avatar asked Nov 26 '18 08:11

Moritz Rinow


People also ask

How do you set multiple environment variables in Postman?

To set up Postman environment variables: In the top right corner of Postman, click the environment selector and select Manage environments. Click Add to add a new environment where you'll define your OneLogin environment variables. Note: You'll need to use your API credentials to generate the access_token value.

Can we import environment variables in Postman?

You can access your environment variables from Postman and from your request elements, including the URL, parameters, body data, and test scripts. For the list of all your environments, select Environments in the sidebar.

What is PM environment in Postman?

The pm object provides functionality for testing your request and response data, with the postman object providing additional workflow control.

How do I add a dynamic variable to my Postman?

A dynamic variable name starts with '$. ' In the request URL section, a dynamic variable should be written in {{__}} format. Let's say you have to pass an integer number from 1 to 1000, so for that, you need to add {{$randomInt}}.


1 Answers

You could do it but I wouldn't recommend it, just seem like you're missing the benefit creating a set of variables and then changing the values of these by selecting a different environment file.

Add this string {{ElasticsearchProtocol}}://{{ElasticsearchServer}}:{{ElasticsearchPort}} as the ElasiticsearchUrl variable, on the environment file.

Postman URL

Or you could add this to the Pre-Request Script:

let ElasticsearchProtocol   = pm.environment.get('ElasticsearchProtocol')
let ElasticsearchServer     = pm.environment.get('ElasticsearchServer')
let ElasticsearchPort       = pm.environment.get('ElasticsearchPort')

pm.environment.set("ElasticsearchUrl", `${ElasticsearchProtocol}://${ElasticsearchServer}:${ElasticsearchPort}`)

Postman Pre Request

like image 157
Danny Dainton Avatar answered Oct 16 '22 03:10

Danny Dainton