# Adding a request (json) body in a simualtion

**URL:** <https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546>\
**Category:** Gatling (Open-Source)\
**Created:** [October 15, 2014, 11:25am UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546 "2014-10-15T11:25:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [October 15, 2014, 11:25am UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/1 "2014-10-15T11:25:57Z")

</div>

Hello,  
I am using ELFileBody to feed my simulation with data like this:

`

class LoginSimulation extends Simulation {

val httpConf = http  
.baseURL([https://mysite.start.com](https://mysite.start.com/))  
.acceptEncodingHeader(“gzip,deflate”)  
.baseHeaders(Map(“X-Token” → “1234asdf”, “Content-Type” → “application/json”, “charset” → “UTF-8”))

val scn = scenario(“Scenario”)

.exec(  
http(“activateUser”)  
.post("/user/activate")  
.body(ELFileBody(“activateUser.txt”))  
.check(status.is(200))  
.check(jsonPath("$.resultCode").is(“SUCCESS”)))

`

The file “activateUser.txt” looks like this:

`{"offerId": "123", "membershipId": "123", "osName": "iOS", "osVersion": "8.02"}`

Can I just add lines in the file like this:

`{"offerId": "123", "membershipId": "123", "osName": "iOS", "osVersion": "8.02"} {"offerId": "124", "membershipId": "124", "osName": "iOS", "osVersion": "8.02"} {"offerId": "125", "membershipId": "125", "osName": "iOS", "osVersion": "8.02"} {"offerId": "126", "membershipId": "126", "osName": "iOS", "osVersion": "8.02"}`

and how do I tell Gatling to change to the next line in the test datafile?

Magnus

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [October 15, 2014, 11:55am UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/2 "2014-10-15T11:55:15Z")

</div>

If I do not want to use ELFile but just plain parameters how can I say:

{“offerId”: “123”, “membershipId”: “123”, “osName”: “iOS”, “osVersion”: “8.02”}

in the body part below?

`.exec( http("activateCoupon") .post("/coupon/activate") .body("?") .check(status.is(200)) .check(jsonPath("$.resultCode").is("SUCCESS")))`

can I say

`.body("{"offerId": "${param1}", "membershipId": "${param2}", "osName": "iOS", "osVersion": "8.02"}")`

and refer to i.e. .csv files in my project?

Magnus

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [October 15, 2014, 12:17pm UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/3 "2014-10-15T12:17:59Z")

</div>

Absolutely.  
ELFileBody is for templating.

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [October 15, 2014, 12:36pm UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/4 "2014-10-15T12:36:27Z")

</div>

Can I also refer a parameter inside the template?  
Given a template file with contents like:

{“offerId”: “123”, “membershipId”: “123”, “osName”: “iOS”, “osVersion”: “8.02”}

can I say

{“offerId”: “123”, “membershipId”: “${memberID}”, “osName”: “iOS”, “osVersion”: “8.02”}

and refer to a csv file I have?  
So then I first refer the template (.body(ELFileBody(“activateCoupons.json”)).asJSON), then I refer the .csv file form the template (“membershipId”: “${memberID}”), and then I have a .csv file looking like this:

memberID  
123  
124  
125  
126

?

If I want more colums in my tesdata .csv file can I just use a Space between them like this:

memberID, offerId  
123, 123  
124, 124  
125, 125  
126, 126

Thank you!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [October 15, 2014, 12:49pm UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/5 "2014-10-15T12:49:54Z")

</div>

> So then I first refer the template  
> (.body(ELFileBody("activateCoupons.json")).asJSON), then I refer the .csv  
> file form the template ("membershipId": "${memberID}"), and then I have a  
> .csv file looking like this:
> 
> memberID  
> 123  
> 124  
> 125  
> 126

Yeah, of course, that's what ELFileBody is for.  
Try it for yourself.

> If I want more colums in my tesdata .csv file can I just use a Space  
> between them like this:
> 
> memberID, offerId  
> 123, 123  
> 124, 124  
> 125, 125  
> 126, 126

No space. CSV doesn't imply trimming the values.

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [October 15, 2014, 1:07pm UTC](https://community.gatling.io/t/adding-a-request-json-body-in-a-simualtion/1546/6 "2014-10-15T13:07:17Z")

</div>

Sweet, it is working great!
