# How to update collection variable when a scheduled run occurs?

**URL:** <https://community.postman.com/t/how-to-update-collection-variable-when-a-scheduled-run-occurs/46201>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, authentication\
**Created:** [April 11, 2023, 11:40am UTC](https://community.postman.com/t/how-to-update-collection-variable-when-a-scheduled-run-occurs/46201 "2023-04-11T11:40:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrnate592](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@mrnate592](https://community.postman.com/u/mrnate592)\
**Post date:** [April 11, 2023, 11:40am UTC](https://community.postman.com/t/how-to-update-collection-variable-when-a-scheduled-run-occurs/46201/1 "2023-04-11T11:40:46Z")

</div>

Hey there, so my API requires an access token and it needs to be refreshed every hour. So I set a scheduled run for it. However, it doesn’t update the variable. I’ve tried this with collection, global and environment variables and nothing seems to work. Here’s the code I used. It prints the correct stuff to console but just wouldn’t update the variable.

let responseBodyJSON = pm.response.json();

///pm.environment.set(“access\_token”, responseBodyJSON.access\_token);

pm.collectionVariables.set(“authtoken”, responseBodyJSON.access\_token);  
console.log("Access token: " + pm.collectionVariables.get(“authtoken”));
