Having trouble with POST call with list in body

Hi,

I’m using Gatling 3.2.1 and having problems calling a method with a list as parameter.

The list is saved as “IdsLettresRecrutement” from a previous call and then used in the body of the next call.

The method is called correctly but the list is parameters is always null.

val obtenirLettreRecrutementAProduire = http("Obtention des lettres de recrutement à produire")
  .get(urlServeurRequete + contexte + "/RequeteLettreRecrutement/ObtenirAProduire?sort=NAM-asc&page=1&pageSize=1000&group=Lettres-asc&aggregate=Lettres-count&filter=")
  .headers(Headers.headerRequete(url))
  .check(status.in(CodesHttp.serveurRequeteOK))

val scn = 
 .exec(obtenirLettreRecrutementAProduire
  .check(jsonPath("$..Items[*].Id").findAll.saveAs("idsLettresRecrutement")))
  .exec { session =>
 .doIf("${idsLettresRecrutement.exists()}")
 {
  // Production des lettres
  exec(http("Production des lettres de recrutement")
   .post(contexte + "/LettresRecrutement/Produire")
   .headers(Headers.headerPostFormulaire)
   .body(StringBody("""{ "guidsDocumentsSelectionnes":"${idsLettresRecrutement}" }""")).asJson
   .check(status.in(CodesHttp.ok))
   .check(jsonPath("$.DemandeProductionDocumentId").find.optional.saveAs("demandeProductionDocumentId"))
  )

Hi Francois,

If you turn on debug logging in Gatling, you can see what your EL expands to.

To properly put a list in a JSON, try using jsonStringify in the EL.

“”"{ “guidsDocumentsSelectionnes”: ${idsLettresRecrutement.jsonStringify()} }"""

Notice that there is no quotes surrounding the JSON array.

These two pages of the documentation are helpful:
https://gatling.io/docs/current/general/debugging/#logback

https://gatling.io/docs/current/session/expression_el/

Regards,
George