# SendRequest in a Pre-request Script on Collection - how to get response to set Collection Variable

**URL:** <https://community.postman.com/t/sendrequest-in-a-pre-request-script-on-collection-how-to-get-response-to-set-collection-variable/40211>\
**Category:** Help Hub\
**Tags:** variables, collections, json\
**Created:** [October 19, 2022, 9:57am UTC](https://community.postman.com/t/sendrequest-in-a-pre-request-script-on-collection-how-to-get-response-to-set-collection-variable/40211 "2022-10-19T09:57:25Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dacreator](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@dacreator](https://community.postman.com/u/dacreator)\
**Post date:** [October 21, 2022, 7:36am UTC](https://community.postman.com/t/sendrequest-in-a-pre-request-script-on-collection-how-to-get-response-to-set-collection-variable/40211/4 "2022-10-21T07:36:03Z")

</div>

Hi MDJones,

thanks for your detailed help!  
I pasted your code into the Collection Pre-Script and updated my parameters and saved the changes.  
When I POST a request in the collection, no error is generated, status 200.  
But I can see that the Collection Variable CollRefToken is not being updated.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/5/0563eaf1c8e7cb1eea3a4bce5c997388492e3912.png)

What is strange that in the request, the variable value of CollRefTokenDev (Refreshed Token should be used as Auth), still has an old value.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/b/7b12c9b002d7a5ccfbf86bb7d99773f0b486dee2.png)

Does the Cookie play a role here? Generally, I want to use the refreshed Token in the Collection Variable CollRefTokenDev for every request, and not some value stored in a cookie.

CURL of request:

```auto
curl --location --request POST 'URL' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGcXXXXXX' \
--header 'Cookie: 5cfd47a23da9b9e1c98a84d0986d03c4=bb651d69ae861b858c8e7b91f7b51002' \
--data-raw '{
"$type": "BLA",
"Message": "Some Message expected to be received and processed by the system",
"MessageType": "BLA"
}'

```

I think this is related to my other post, where there is a Collection using new environment with Cookie (no value update) in comparison with a Collection using an old environment without cookie (value is being updated):

> [@Setting Collection Variable doesn't work](https://community.postman.com/t/setting-collection-variable-doesnt-work/40305):
>
> My question: I have 2 collections. In C1 I send a request to get the response value of “access\_type” and set its value in the Collection variable “CollRefToken”. This works fine. every time I POST the request, the current value of CollRefToken is being updated. The Code to set the CollVar is under “Tests” in the POST request. In C2 I want to do the same. Same code, but here the Collection variable is not being updated. The request runs without error in both collections. Details (like screen…

Thanks

---

_[View the full topic](https://community.postman.com/t/sendrequest-in-a-pre-request-script-on-collection-how-to-get-response-to-set-collection-variable/40211)._
