Back to all posts
postman api programming

Postman Environment Variables

1 min read (208 words)

Using Environment in Postman is one of the best things that we can use during the testing and while playing around with API. Postman makes this development phase much easier.

API is getting more to the token-centric authentication and Environment Variable becomes handy.

I will use Cisco Sandbox for my examples, that is one of the great ways to get some practice with Cisco products API.

Setting up Postman Environment Variables:

Postman interface showing environment variable setup process with Cisco Sandbox example

Using them in API requests with {{variable name}} :

Postman request using environment variables with {{variable name}} syntax

Sometimes the service itself generates Access Token and provides in the body or header. I used to just copy it from the header into all other requests.

API response showing access token in response headers

But there is a better way to do it. Using Tests in the Token Generation request we can set the Variable from the body/header and it will be set as a normal Environment Variables, no more copy-paste.

The response with the Token and Domain looks like this:

JSON response containing token and domain information from API

In the following example we set the fmc_access_token environment variable from header "X-auth-access-token" and DOMAIN_UUID variable from header "DOMAIN_UUID" using Tests:

Postman environment variables interface showing test automation with API tokens

And now we have those variables as CURRENT VALUE in our environment ready to use in other requests:

Postman environment showing current values of API access tokens and domain variables
Postman environment variables list showing configured API testing parameters

It's very useful when you have a collection of different requests set up with variables.

Dmitry Golovach
About

Dmitry Golovach

Principal Network Engineer and AI enthusiast. Always learning, always building.

Share this post

All posts