# Accessing session values when calling regular methods

**URL:** <https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330>\
**Category:** Gatling (Open-Source)\
**Created:** [August 27, 2014, 2:02am UTC](https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330 "2014-08-27T02:02:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wayne\_Izatt](https://avatars.discourse-cdn.com/v4/letter/w/ba9def/32.png) [@Wayne\_Izatt](https://community.gatling.io/u/Wayne_Izatt)\
**Post date:** [August 27, 2014, 2:02am UTC](https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330/1 "2014-08-27T02:02:46Z")

</div>

Hello, I have a scenario that executes the following to get some values:

val getToken = feed(Properties.userCredentials)  
.exec(  
http(“GetToken”)  
.post(…)  
.header(“Content-Type”, “application/x-www-form-urlencoded”)  
.header(…)  
.queryParam(…)

.check(headerRegex(“tuidsession”, “(.\*)”).exists.saveAs(“sessionKey”))

.check(headerRegex(“userid”, “(.\*)”).exists.saveAs(“userId”)))

.exec(Pause.reqPause)

The values I’m interested in “userId” and “sessionKey”, and I know that they are being returned correctly.

In a subsequent call, I need to make the value of “userId” and “sessionKey” available to a method call to build a string prior to executing a Gatling API:

val uploadSDl = exec(  
http(“UploadSD”)  
.post(…)  
.header(…)  
.header(“sdsignature”, CryptoUtils.sign(“POST /users/” + session(“userId”).as[String] + “/tuid/” + Properties.tuid + “/upload”, session(“sessionKey”).as[String]))

.header(“Content-Type”, “multipart/form-data; boundary=---------------------------1234567890”)  
.formUpload(“video”, Properties.smallFlvFileName))

.exec(Pause.reqPause)

However, I don’t seem to be able to access the values in the session:

session(“userId”).as[String]

and

session(“sessionKey”).as[String]

both give me the error: “not found value session”

I’ve also tried the underscore approach, to no avail.

How do I get at those values?

thanks  
Wayne

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [August 27, 2014, 6:21am UTC](https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330/2 "2014-08-27T06:21:55Z")

</div>

Hi Wayne,

The problem is that you’re using the session the fetch the userId and sessionKey, but you’re not telling where it’s coming from.  
Simple add _session =\>_ before your call to CryptoUtils.sign :

.header(“sdsignature”, session =\> CryptoUtils.sign(“POST /users/” + session(“userId”).as[String] + “/tuid/” + Properties.tuid + “/upload”, session(“sessionKey”).as[String]))

Cheers,

Pierre

---

<div class="post-metadata">

**Author:** ![Wayne\_Izatt](https://avatars.discourse-cdn.com/v4/letter/w/ba9def/32.png) [@Wayne\_Izatt](https://community.gatling.io/u/Wayne_Izatt)\
**Post date:** [August 27, 2014, 3:29pm UTC](https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330/3 "2014-08-27T15:29:15Z")

</div>

Thanks, Pierre - that is indeed what I needed!

cheers  
Wayne

---

<div class="post-metadata">

**Author:** ![rreynolds](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rreynolds](https://community.gatling.io/u/rreynolds)\
**Post date:** [March 11, 2015, 8:33pm UTC](https://community.gatling.io/t/accessing-session-values-when-calling-regular-methods/1330/4 "2015-03-11T20:33:59Z")

</div>

Thank you so much for answering this!

-Ryan
