Need help with scala String substitution when Gatling EL used

Hello,

Could you please help with String variable “cardNumber” substitution in following scenario.

In following scenario except cardNumber, rest of variables are read from CSV file which seem to use Gatling DSL.
how to enable string substitution only for cardNumber in this context.

private def sendAuthenticationRequest(merchantId: String, cardNumber: String) = {

http(“Authentication”)
.put( “”"/api/rest/version/${version}/merchant/""" + merchantId + “”"/order/${oid}/transaction/""" + tId)
.basicAuth(“merchant.” + merchantId, “${apipassword}”)
.body(StringBody(
“”"{
“apiOperation”: “AUTHENTICATION”,
“sourceOfFunds”: {
“provided”: {
“card”: {
“number”: s"${cardNumber}", // This method does not seem to enable Scala string substitution
}
}
}

}""".stripMargin)
)

.check(status.is(SC_CREATED))
.check(jsonPath("$…result").find.is(“SUCCESS”))

}

When I try to run this, getting error as "No attribute named ‘cardNumber’ is defined

Best Regards,
Raja

Hopefully one of the resident pro’s can give you a better answer then me, but would putting the cardNumber into session and then using the EL work?

if you’re intending to use the same cardNumber for each execution (as you are for merchantId), you just need to have your StringBody as…

s"""{
“apiOperation”: “AUTHENTICATION”,
“sourceOfFunds”: {
“provided”: {
“card”: {
“number”: “$cardNumber”, // This method does not seem to enable Scala string substitution
}
}
}

}""".stripMargin)

I think you can not pass cardNumber string variable directly to request body.

You need first save string variable into session then pass the session variable to request body.

exec(session => {
session.set(“cardNumber”,cardNumber)
})

Execute this before request body