I have a gatling code below where I want the value of the listingid in the response of the first api be passed to the request of the second api. However, only the first api is successful. Kindly help.
class ClassifiedGenerator extends Simulation{
// protocol
val httpProtocol: HttpProtocolBuilder = http
.baseUrl("https://url.com")
// scenario
//first api
val createlistingidscn: ScenarioBuilder = scenario("create listingid")
.exec(
http("create listingid")
.post("/api/Listing")
.header("accept", "application/json")
.body(RawFileBody("src/test/resources/testCreateClassified.json")).asJson
.check(
status is 201,
jsonPath("$.listingId").saveAs("listingId")
)
)
//second api request
val publishlistingidscn: ScenarioBuilder = scenario("publish listingid")
.exec(
http("publish listingid")
.put("/api/Listing/PublishByAgencyId")
.header("accept", "application/json")
.body(StringBody(s"""{
| "agencyId": 240565, //hardcode
| "publicationTypeId": 2, //hardcode
| "listingIds": [
| ${listingId} //variable value of listingid from the response of the first api
| ]
|}""".stripMargin)).asJson
)
//setUp
setUp(
createlistingidscn.inject(atOnceUsers(1)),
publishlistingidscn.inject(atOnceUsers(1))
).protocols(httpProtocol)
}