# Parameter i JSON request body pointing to .csv file

**URL:** <https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715>\
**Category:** Gatling (Open-Source)\
**Created:** [November 17, 2014, 2:59pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715 "2014-11-17T14:59:05Z")\
**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:** [November 17, 2014, 2:59pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/1 "2014-11-17T14:59:05Z")

</div>

Hello,  
I have a JSON request body looking like this:

`  
{“offerId”: “${offerId}”, “membershipId”: “${memberID}”, “osName”: “Android”, “osVersion”: “4.4”}

`

and a testdata file with this content:

`

memberID,offerId  
8107222059,000C297765971EE495BE0BA921A125F7  
8107222052,000C297765971EE495BE0BA921A125F7

`

`

val scn = scenario(“Scenario”)

.feed(csv(“memberInfo.csv”).random)

.exec(\_.set(“TOKEN”, “${memberID}”))

.exec(  
http(“buyGift”)  
.post("/gift/buy")  
.header(“X-Token”, “${TOKEN}”)  
.body(ELFileBody(“buyGift.json”)).asJSON  
.check(status.is(200))  
.check(jsonPath("$.resultCode").is(“SUCCESS”))  
)

}

`

But when I enable logging the log states:

`

Request:  
getProfile: OK

---

<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:** [November 17, 2014, 3:08pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/2 "2014-11-17T15:08:17Z")

</div>

Hi Magnus,

When you set manually a value in the session using _set(name, value)_, like you did with _.exec(\_.set(“TOKEN”, "${memberID}”)),_ _value_ cannot be a EL string.  
But then, why don’t simply write _.header(“X-Token”, “${memberID}”)_ ?

Cheers,

Pierre

---

<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:** [November 17, 2014, 3:28pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/3 "2014-11-17T15:28:40Z")

</div>

Hi Pierre,  
Ok, but will Gatling then use the same line in my testdatafile when I do like below? Will the two highlighted red **${memberID}** refer to the same row in the testdatafile?

`

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import scala.concurrent.duration.\_

class XSimulation extends Simulation {

val httpConf = http  
.baseURL(“[https://myapp.sweet.se](https://myapp.sweet.se)”)  
.acceptEncodingHeader(“gzip,deflate”)  
.headers(Map(“Content-Type” → “application/json”, “charset” → “UTF-8”, “User-Agent” → “Android(4.4)/Sweet(0.4)/0.1”))

val scn = scenario(“Scenario”)

.feed(csv(“memberInfo.csv”).random)

.exec(  
http(“getProfile”)  
.get("/user/profile")  
.header( “X-Token”, “ **${memberID}** ” )  
.check(status.is(200))  
.check(jsonPath("$.resultCode").is(“SUCCESS”))  
)

.exec(  
http(“getGiftList”)  
.get("/gift/all")  
.header(“X-Token”, “ **${memberID}** ”)  
.check(status.is(200))  
.check(jsonPath("$.resultCode").is(“SUCCESS”)))

setUp(scn.inject(constantUsersPerSec(1) during (1 minutes))).protocols(httpConf)

}

`

---

<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:** [November 17, 2014, 3:30pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/4 "2014-11-17T15:30:59Z")

</div>

Short answer: yes.  
Long answer: yes, as long as you do not add another _.feed(csv(“memberInfo.csv”).random)_ between your _execs_.

---

<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:** [November 17, 2014, 4:28pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/5 "2014-11-17T16:28:49Z")

</div>

and if I have a json-body like this:

`

{“offerId”: “${offerId}”, “membershipId”: “ **${memberID}** ”, “osName”: “Android”, “osVersion”: “4.4”}

`

I can say:

`

.exec(  
http(“activateGift”)  
.post("/gift/activate")  
**.header(“X-Token”, “${memberID}”)**  
.body(ELFileBody(“ **activateGift.json** ”)).asJSON  
.check(status.is(200))  
.check(jsonPath("$.resultCode").is(“SUCCESS”))  
)

`

and it will pick up memberID first as a header _and_ then as a value inside my request (json-body), both being the same row in the testdata .csv file? right.

I can use it both as a direct parameter within my exec ( .header(“X-Token”, “${memberID}”)) and inside son body like this:

{“offerId”: “${offerId}”, “membershipId”: “ **${memberID}** ”, “osName”: “Android”, “osVersion”: “4.4”}

?

Magnus

---

<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:** [November 17, 2014, 4:57pm UTC](https://community.gatling.io/t/parameter-i-json-request-body-pointing-to-csv-file/1715/6 "2014-11-17T16:57:49Z")

</div>

Yes you can.  
As long as you do not add another _feed(…)_ call in your scenario, the same record will be used throughout the scenario, as many times as you want.
