# Refresh Access Token

**URL:** <https://community.gatling.io/t/refresh-access-token/9526>\
**Category:** Gatling (Open-Source)\
**Created:** [January 28, 2025, 9:18am UTC](https://community.gatling.io/t/refresh-access-token/9526 "2025-01-28T09:18:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthiks](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@karthiks](https://community.gatling.io/u/karthiks)\
**Post date:** [January 28, 2025, 9:18am UTC](https://community.gatling.io/t/refresh-access-token/9526/1 "2025-01-28T09:18:42Z")

</div>

I am unable to refresh token. below is my code. After the 2nd minute the proxyToken variable is refreshed and the new value is printed. However the same is not getting passed into the ‘Proxy Service’ header. This works fine for the first time but i am facing issue only from the second call onwards when i need to refresh the token. Please help…

Edit, More info : The print statement prints the new token at the 120th sec(2nd run after the pause) but this new token does not transfer to the api call like it does in the first one(0th second)

```scala
var proxyToken = "proxy"

val apiCallSmall = exec( http("Accounts API")
    .get(authzUri.toString)
    .headers(Map(
      "Resource-Scope" -> "Managed",
      "Proxy-Service" -> "${proxyToken}",
      "accept" -> "application/json"
    ))
    .check(status.is(200))
  )

  val smallScenario = scenario("Small Partner scenario")
    .exec(_.set("proxyToken", proxyToken))
    .exec(apiCallSmall)

  val getProxyScenario = scenario("Get proxy token scenario")
.exec(_.set("access_token", generateSSAV2Token()))
.exec(session => {
      proxyToken = session("access_token").as[String]
      println(s"Response body Proxy Scenario is:::::::::::: :::> \n$proxyToken")
      session
    })
    .pause(2.minutes)

```

Simulation code

```scala
setUp(
    getProxyScenario.inject(
        constantConcurrentUsers(1).during(totalDuration.minutes)
      )
      .protocols(httpProtocol),
    getUATScenario.inject(
        constantConcurrentUsers(1).during(totalDuration.minutes)
      )
      .protocols(httpProtocol),
    smallScenario.inject(
        nothingFor(40.seconds),
        atOnceUsers(10)
      )
      .throttle(
        reachRps(1).in(5.seconds),holdFor(5.minutes),
        jumpToRps(1),holdFor(15.minutes)
      )

```

---

<div class="post-metadata">

**Author:** ![karthiks](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@karthiks](https://community.gatling.io/u/karthiks)\
**Post date:** [January 28, 2025, 9:48am UTC](https://community.gatling.io/t/refresh-access-token/9526/2 "2025-01-28T09:48:21Z")

</div>

I have also tried with var and def for all the methods above but still the same

---

<div class="post-metadata">

**Author:** ![trinp](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/trinp/32/1593_2.png) [@trinp](https://community.gatling.io/u/trinp)\
**Post date:** [January 28, 2025, 10:22am UTC](https://community.gatling.io/t/refresh-access-token/9526/3 "2025-01-28T10:22:21Z")

</div>

you may want to check here

> <https://github.com/gemiusz/gatling-examples-maven-java/blob/master/src/test/java/pl/gemiusz/Case0022SetOrRefreshTokenSimulation.java>

Shout out to @GeMi

---

<div class="post-metadata">

**Author:** ![karthiks](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@karthiks](https://community.gatling.io/u/karthiks)\
**Post date:** [January 28, 2025, 11:05am UTC](https://community.gatling.io/t/refresh-access-token/9526/4 "2025-01-28T11:05:02Z")

</div>

Thank you for replying. I believe i am doing something similar in my code but its not working…

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 28, 2025, 8:50pm UTC](https://community.gatling.io/t/refresh-access-token/9526/5 "2025-01-28T20:50:15Z")

</div>

Please provide a full sample. Just reading your partial sample, I can’t spot anything wrong but some pieces are missing.

---

<div class="post-metadata">

**Author:** ![karthiks](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@karthiks](https://community.gatling.io/u/karthiks)\
**Post date:** [January 29, 2025, 4:59am UTC](https://community.gatling.io/t/refresh-access-token/9526/6 "2025-01-29T04:59:06Z")

</div>

Thank you for responding. May i know which part you want more clarity on - the parts not shown here are working fine so i didnt share that.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 29, 2025, 8:07am UTC](https://community.gatling.io/t/refresh-access-token/9526/7 "2025-01-29T08:07:24Z")

</div>

Several persons hava had a look at your code extracts and can’t see the issue.  
At this point, we absolutely need a reproducer we can run on our side as [described here](https://stackoverflow.com/help/minimal-reproducible-example) so we can investigate.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [February 28, 2025, 8:07am UTC](https://community.gatling.io/t/refresh-access-token/9526/8 "2025-02-28T08:07:30Z")

</div>

Closed on February 28, 2025, 8:07am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
