Not able to send unique requests.

I am new to Gatlng and I am not able to find a good way to parameterize my json payload while doing a POST. I have to make as many unique POST calls to the rest api. So I have function which does that , look at the method getSomeData() . I use json4s to manipulate json payload. I am expecting that the json payload in my post request would be constructed each time a api call is made. But what seems to happen is , the method ``getSomeData is just called once and the data is updated in my json and the same data is used to run test which defeats my purpose. Is there any way to make this work. I am expecting that each request i make in through my scenario and setup, it gathers new data each time.

object GetPayloadData {}

def getSomeData(): String = {

// I am using Json4s to handle json.

val r = scala.util.Random
val lines =“src/test/resources/bodies/SomeJson.json”).mkString
val Json = parse(lines).transformField {
case (“startDate”, date) => (“startDate”, + “T00:00:00-07:00”)
case (“endDate”, endDate) => (“endDate”, + “T00:00:00-07:00”)
case (“numOfAdults”, numOfAdults) => (“numOfAdults”, r.nextInt(100)) //I use scala utils random to get these values
case (“numOfWhatver”, numOfChildren) => (“numOfWhatever”, r.nextInt(100))

return (compact(render(Json)))


class SearchSimulation extends Simulation {

val Search_Api_Json = “SimpleSearch.json”
val searchPayLoad = new GetPayloadData

val httpConf = http
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”) // Here are the common headers
.acceptEncodingHeader(“gzip, deflate”)
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val scn = scenario(“SearchDataLoading”) // A scenario is a chain of requests and pauses
.exec(http(“Search_Request”) // Here’s an example of a POST request

atOnceUsers(10), // 2
rampUsers(600) over (60 seconds) // 3


If I’m not mistaken, the answer to your question was posted a few days ago:

yes it does look similar. But i am trying to build the JSON body as string and passing it through as payload. But in the example

.body(StringBody(_ => “”"{“name”:"""" + Name.first_name.toLowerCase + “”"",“age”:""" + ThreadLocalRandom.current().nextInt(10, 80) + “”"}"""))

and I am trying to do it as :


Please try simply transforming your call to lambda:

.body(StringBody(_ => searchPayLoad.getSomeData())).asJSON



@adam : Thanks.

For some reason , i tried that before posting it to this group. And I must be tired enough I did not see it working , until I checked back again. I am new to scala and gatling; why is this not very evident from the documentation or is it not the way one should approach the tests?