I am trying to get productId from a json response and use it in the subsequent request. I am able to get its value within the session lambda but it is not available outside of it.
val postQueriesProductsHttp = http(“PostQueriesProducts”)
.post("/v2/queries/products?include=products.basic-information")
.body(StringBody(s"""{
“queries”: [{
“id”: “properties”,
“values”: [“ABCDE”]
},
{
“id”: “start-date”,
“values”: [“2016-11-03”]
},
{
“id”: “length-of-stay”,
“values”: [“2”]
},
{
“id”: “quantity”,
“values”: [“1”]
},
{
“id”: “number-in-party”,
“values”: [“3”]
},
{
“id”: “rate-request-types”,
“values”: [{
“type”: {
“code”: “standard”
},
“value”: “”
}]
}]
}"""))
.check(status.is(200))
val postCartsHttp = http(“PostCarts”)
.post("/v2/carts")
val postCarts = scenario(“PostQueriesProducts”)
.exec(postQueriesProductsHttp.check(jsonPath("$…id").saveAs(“productId”)))
.exec(session => {
println(session(“productId”).asOption[String])
var productId = session.get.attributes(“productId”).toString()
println(productId)
session
})
.exec(postCartsHttp
.body(StringBody(s"""{
“consumerId”: “”,
“productId”: “${productId}”,
“quantity”: 1,
“addOns”: [{
“id”: “C2”,
“startDate”: “2016-11-03”,
“endDate”: “2016-11-04”,
“ordinal”: 1
}]
}"""))
.check(status.is(200)))
}