how to pass Dynamic values through file in REST API request

Hi,

I am having REST API Request, Where User ID be dynamic and should fetch the values for file.

{
“UserID” : (need to pass the values from file over here for checking the performance of the API)
“events”: [
{
“eventType”: “ABCD”,
“account”: “ABCD”,
}
}

Can I get the help on this I tried using feeder but couldn’t able to get the proper response.

Try using feeders.

you can use feeders. One of the file type that feeder support is csv. first row of your file must contain the labels or parameter names that you are going to use in request call. keep your feeder file in gatling directory searc for data folder. You may find here <gatling_installation directory>/user-files/data.

ex. val data_feeder = csv("<filename.csv>")

val scn = scenario(“Test”)
.feeder(data_feeder)
.exec(http(“your request”)

)

This is how you can use labels that you provided in csv.

{
“UserID” : "${id}"
“events”: [
{
“eventType”: “${type}”,
“account”: “${acc}”,
}
}

Hi Rohit,

I tried the below code to execute but getting an error stating “value feeder is not a member of io.gatling.core.structure.ScenarioBuilder”, can you please let me know where its lagging?

Class Test extends Simulation {
val httpConf: HttpProtocolBuilder = http
.baseURL(“https://XXXXXX.net”)
.contentTypeHeader(“application/json”)

val data_feeder = csv(“File.csv”)

val stringBody: String =
“”"

{
“customerID”: “${CustomerID}”,
“events”: [
{
“eventType”:
},
{
“eventType”: “monetate:context:PageView”,


},
{
“eventType”: “”,
“metadata”:
{




}
}
]
} “”".stripMargin
val scn: ScenarioBuilder = scenario(“Scenario 1”)
.feeder(data_feeder)
.exec(http(“Request”)
.post("/")
.body(StringBody(stringBody))
.check(status.is(200)))

setUp(scn.inject(atOnceUsers(50)).protocols(httpConf))
}

Hi Aaryan,
do u have this statement in import, if no then try adding this

import io.gatling.core.structure.{ScenarioBuilder}

let me know this fixes your problem

Hi Rohit,

Its picking up the value snow but I want to ensure that whether it is taking the different values each time for each API call.
Is there any way where we can store the each request send to the API endpoint and the response which we get from sending the API request.

Hi Aaryan,

I got little confused now.
what I have understood is, you are calling ‘request1’ by passing some dynamic values and you want to verify the same values that you have passed to ‘request1’ which are populated in ‘request2’ or not? Is this what you are trying to achieve?