> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/programming/postman/environment-variables.md).

# 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:

<figure><img src="https://3885248957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoE4wMO1dMVDOGDjh0En7%2Fuploads%2FpkJhLmmrPQXlsac9Qu6R%2Fimage.png?alt=media&amp;token=20e3103f-135f-41c0-9ce6-e4666d7d8fc7" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3885248957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoE4wMO1dMVDOGDjh0En7%2Fuploads%2FVFnTNomod4DLJNX6E3zI%2Fimage.png?alt=media&amp;token=813710f1-e4e2-41e6-9cdb-afaf4e1ec5ad" alt=""><figcaption></figcaption></figure>

#### 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 <mark style="color:orange;">`login`</mark> path operation as to define it directly as you log in
* Navigate to the <mark style="color:orange;">`Tests`</mark> tab and select <mark style="color:purple;">`Set an environment variable`</mark>
* Use the following code to set it dynamically

```python
pm.environment.set("JWT", pm.response.json().access_token);
```

* The above code sets the environment variable as <mark style="color:orange;">`JWT`</mark> 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&#x20;
* In our case <mark style="color:orange;">`access_token`</mark> but can be anything as it's app defined under the route return

<figure><img src="https://3885248957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoE4wMO1dMVDOGDjh0En7%2Fuploads%2F5xtPzG10Yrl4f0i2YpZm%2Fimage.png?alt=media&amp;token=cc223060-4b16-4844-915e-4637ea9d15f5" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3885248957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoE4wMO1dMVDOGDjh0En7%2Fuploads%2FJRQhFa2G7XndjDa6Y98a%2Fimage.png?alt=media&amp;token=2021c6de-ac5a-4a14-bcb2-ec87deb16ceb" alt=""><figcaption></figcaption></figure>
