Environment Variables
Environment variables allow developers to switch between DEV and PROD for example
It allows for definition of different variables based on needs
Allows to define variables dynamically
To define Environment variables such as the URL:

After this has been defined, you can call it in the operation path:

It also became harder to test our API since we have added the login logic and protected routes
So to save some time, we can automate the definition of the JWT as an environment variable through code
This should be done under the
loginpath operation as to define it directly as you log inNavigate to the
Teststab and selectSet an environment variableUse the following code to set it dynamically
pm.environment.set("JWT", pm.response.json().access_token);The above code sets the environment variable as
JWTwith the value fetching first the response, then transforming it into a JSON output from which the variable named in the return output is calledIn our case
access_tokenbut can be anything as it's app defined under the route return

After this is defined, we can call it under the authorization tab as
{{JWT}}to always have it update on login

Last updated