# How to put variable in http body

**URL:** <https://community.gatling.io/t/how-to-put-variable-in-http-body/2631>\
**Category:** Gatling (Open-Source)\
**Created:** [October 22, 2015, 1:51pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631 "2015-10-22T13:51:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Piskunov](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@Sergey\_Piskunov](https://community.gatling.io/u/Sergey_Piskunov)\
**Post date:** [October 22, 2015, 1:51pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/1 "2015-10-22T13:51:30Z")

</div>

```auto
I save necessary information in "identity_id_B" and need to send it in the next request body.
How can i save this info in variable?
Thanks in advance

```

```auto

```

```auto

```

```auto

 .exec(http("Create id user B")
 .post(URL)
 .body(StringBody(session => "...")).asJSON
 
 .check(jsonPath("$.identityId")
 .saveAs("identity_id_B"))
  )

 exec(http("Send invite")
  .post(OTHER_URL)
  .headers(sentHeaders_A)
  .body(StringBody(session => "{\"invitee\":\"" + identity_id_B!! + "\",\"message\":\user B\"}")).asJSON
   )
}

```

---

<div class="post-metadata">

**Author:** ![jarrowwx](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jarrowwx](https://community.gatling.io/u/jarrowwx)\
**Post date:** [October 22, 2015, 2:19pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/2 "2015-10-22T14:19:47Z")

</div>

What you are looking for is session variables and expressions…

.body( StringBody( “”"{“invitee”:"${identity\_id\_B}",“message”:“user B”}""" ) )

---

<div class="post-metadata">

**Author:** ![Sergey\_Piskunov](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@Sergey\_Piskunov](https://community.gatling.io/u/Sergey_Piskunov)\
**Post date:** [October 22, 2015, 2:56pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/3 "2015-10-22T14:56:57Z")

</div>

Unfottunately, in this case :.body( StringBody( “”"{“invitee”:"${identity\_id\_B}",“message”:“user B”}""" ) )  
i have **REQUEST BODY: null**

in this one: .body(StringBody( session =\> {"“invitee”:"${identity\_id\_B}",“message”:“user B”"})).asJSON  
**REQUEST BODY: “invitee”:"${identity\_id\_B}",“message”:"user B"**

**maybe i need to create some session variable?**

---

<div class="post-metadata">

**Author:** ![jarrowwx](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jarrowwx](https://community.gatling.io/u/jarrowwx)\
**Post date:** [October 22, 2015, 3:14pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/4 "2015-10-22T15:14:47Z")

</div>

The first request is supposed to be creating the session variable. But you are missing a leading dot on your second exec, which means it is not being chained properly. Add the missing “.” and try again.

---

<div class="post-metadata">

**Author:** ![Sergey\_Piskunov](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@Sergey\_Piskunov](https://community.gatling.io/u/Sergey_Piskunov)\
**Post date:** [October 22, 2015, 3:28pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/5 "2015-10-22T15:28:12Z")

</div>

```auto
.repeat(NUMBER_OF_LOOPS_FOR_GET) {
exec(http("Send invite")
 .post(CONTEXT_URL")
 .headers(sentHeaders_A)
 .body(StringBody( session => {"\"invitee\":\"${identity_id_B}\",\"message\":\"user B\""})).asJSON
 .check(status.is(200))
)}

```

```auto
Its ok in scenario, i missed dot in example(
everything work correctly, but i cant to transfer the value to a variable
I think that its necessary to create a session variable
All i need is to put my saved previously value into body.
But I dont know how

```

---

<div class="post-metadata">

**Author:** ![jarrowwx](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jarrowwx](https://community.gatling.io/u/jarrowwx)\
**Post date:** [October 22, 2015, 3:54pm UTC](https://community.gatling.io/t/how-to-put-variable-in-http-body/2631/6 "2015-10-22T15:54:16Z")

</div>

Re-read my first reply.
