# How is it possible to share values/variables among two sessions in gatling?

**URL:** <https://community.gatling.io/t/how-is-it-possible-to-share-values-variables-among-two-sessions-in-gatling/3353>\
**Category:** Gatling (Open-Source)\
**Created:** [November 1, 2016, 4:57pm UTC](https://community.gatling.io/t/how-is-it-possible-to-share-values-variables-among-two-sessions-in-gatling/3353 "2016-11-01T16:57:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivas\_D](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Srinivas\_D](https://community.gatling.io/u/Srinivas_D)\
**Post date:** [November 1, 2016, 4:57pm UTC](https://community.gatling.io/t/how-is-it-possible-to-share-values-variables-among-two-sessions-in-gatling/3353/1 "2016-11-01T16:57:41Z")

</div>

Hi,

We have a scenario in which the user performs to consecutive requests, which will be like this is pseoducode:

1. http(POST): /createUserSession /\* returns a userSessionId \*/
2. http(POST): /ceateShoppingCart  
.queryParam(“sid”,userSessionId) /\* create a shoppingCart using the userSessionId)

I tried to store the userSessionId as session variable in the first request, and then pass it as a parameter in the second request:

val search =  
exec(http(“getuserSessionID”)  
.post("/session/create")  
.exec(session =\> {session.set(“session\_id”, ((parse( **userSessionId** …)) /\* catching the userSessionId in the first request \*/  
session})

.exec(http(“createShoppingCart”)  
.post("/cart/")  
.queryParam(“sid”,session(“ **userSessionId** ”).as[String] ) /\* passing the stored userSessionId in the second request \*/

However the second request fails as the passed userSessionId is always null, as if it is working with a new session who does not have the userSessionId.  
In gatling, is a **SESSION** created for each **USER** , or each **REQUEST**? Does the second request create a new session?  
How can I share session variables between consecutive requests of a single user?

Would highly appreciate any help!

Regards,  
Srinivas
