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 login path operation as to define it directly as you log in

  • Navigate to the Tests tab and select Set an environment variable

  • Use the following code to set it dynamically

pm.environment.set("JWT", pm.response.json().access_token);
  • The above code sets the environment variable as JWT with the value fetching first the response, then transforming it into a JSON output from which the variable named in the return output is called

  • In our case access_token but 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