# Collection variable not updatable by pos-response script

**URL:** <https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [October 2, 2025, 11:53am UTC](https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242 "2025-10-02T11:53:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/leoschuler/32/33635_2.png) [@leoschuler](https://community.postman.com/u/leoschuler)\
**Post date:** [October 2, 2025, 11:53am UTC](https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242/1 "2025-10-02T11:53:45Z")

</div>

I have created a simple post-response script, the purpose is to request an access token, save that token into a collection variable, which is used as part of the authentication for other requests,

this is the script:

```javascript

// Stores the Token field in an environment or global variable
console.log( "start post response")
var responseBody = pm.response.json();
var token = responseBody.Token;
console.log( token )
pm.collectionVariables.set("token", token);

console.log(pm.collectionVariables.get("token"))

```

the script seem to run fine, the logs show the propper values being retrieved from the responseBody then it is successfully retrieved from collectionVariables.get - BUT after the execution, I check the variable inside the collection ant it is empty.

any idea why?

---

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/leoschuler/32/33635_2.png) [@leoschuler](https://community.postman.com/u/leoschuler)\
**Post date:** [October 2, 2025, 2:24pm UTC](https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242/2 "2025-10-02T14:24:26Z")

</div>

I was able to make it work, I had to include an initial value for the variable, after that the variable worked fine

---

<div class="post-metadata">

**Author:** ![lednik](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lednik](https://community.postman.com/u/lednik)\
**Post date:** [October 2, 2025, 3:07pm UTC](https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242/3 "2025-10-02T15:07:33Z")

</div>

How are you adding initial value ? you cant do that anymore, there is no initial/currnet anymore ?

![image](https://us1.discourse-cdn.com/getpostman/optimized/3X/c/b/cb14db04c172fb91d29ed1125a751dcef49f057c_2_690x45.png)

---

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/leoschuler/32/33635_2.png) [@leoschuler](https://community.postman.com/u/leoschuler)\
**Post date:** [October 3, 2025, 11:51am UTC](https://community.postman.com/t/collection-variable-not-updatable-by-pos-response-script/85242/4 "2025-10-03T11:51:09Z")

</div>

you are correct, there is only a single value column right now, what I meant to say is that I had never included any value before, I had just included the name of the variable and leave the value column empty.

saving a value for the first time in that interface solved the problem, it seems the variable was not properly initialized before I included a value in that column for the first time.

hope that clarifies
