# How to set initial value of variable using pm API

**URL:** <https://community.postman.com/t/how-to-set-initial-value-of-variable-using-pm-api/27175>\
**Category:** Help Hub\
**Tags:** test\
**Created:** [August 26, 2021, 3:28pm UTC](https://community.postman.com/t/how-to-set-initial-value-of-variable-using-pm-api/27175 "2021-08-26T15:28:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ra\_Na](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Ra\_Na](https://community.postman.com/u/Ra_Na)\
**Post date:** [August 26, 2021, 3:28pm UTC](https://community.postman.com/t/how-to-set-initial-value-of-variable-using-pm-api/27175/1 "2021-08-26T15:28:51Z")

</div>

I am trying to use the variable set in environment/Collections as variables in Collection documentation. but i have observed when you set using

```auto
pm.environment.set("some_key", "some_value")

```

sets only the current value field, but the docs section when we use variable as `{{some_key}}` , it always reads from initial value, how to set that without the UI programmatically

---

<div class="post-metadata">

**Author:** ![cmnazario](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/cmnazario/32/10207_2.png) [@cmnazario](https://community.postman.com/u/cmnazario)\
**Post date:** [August 26, 2021, 7:36pm UTC](https://community.postman.com/t/how-to-set-initial-value-of-variable-using-pm-api/27175/2 "2021-08-26T19:36:01Z")

</div>

Hello @Ra_Na  
You can put a condition in the folder’s pre-request in case it doesn’t have a value you define, I’ll put the example below for you to see if it applies to your case:

```auto
if (!pm.environment.get("some_key"))
    pm.environment.set("some_key", "Opa isso é um teste");

```

Note: I talked about putting the test in the folder’s pre-request because it will always run on every request that is inside the folder
