# Unique POST param value for every call

**URL:** https://community.gatling.io/t/unique-post-param-value-for-every-call/6019
**Category:** Gatling (Open-Source)
**Created:** [March 16, 2021, 4:46pm UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019 "2021-03-16T16:46:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Richard\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Richard\_Livingstone](https://community.gatling.io/u/Richard_Livingstone)
#### Post date: [March 16, 2021, 4:46pm UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/1 "2021-03-16T16:46:28Z")

</div>

Hi there

I’m a noob to Scala and Gatling so please bear with - I have read as much of the relevant documentation as I can but still not sure how to do this.

So, I’m writing a simulation to load test a website that requires one field (a request id) to be completely unique every call.

So I generate the value like this, but any method would be ok, I’m sure:

val rqId = “MYLOADTEST\_” + Verification.randomAlpha(20)

(where my randomAlpha function calls util.Random.nextInt but that works, so I’ll not post that bit)

Then:

val scn = scenario(“My test”)  
.exec(  
http(“Payment123JS”)  
.post("")  
.formParam(“requestId”, rqId)  
.formParam(“language”, “en”)

.check(status.is(200))

)

.pause(1)

and finally

setUp(scn.inject(atOnceUsers(10)).protocols(httpProtocol))

So clearly each of these 10 calls is identical, same requestId, so not what I want. But within the simulation there doesn’t seem any way to vary this at all. If I pass in a value, it’s no different. I could use several injectors running independently and change

setUp(scn.inject(atOnceUsers(10)).protocols(httpProtocol))

to

setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))

but there must be a better way?

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [March 16, 2021, 5:07pm UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/2 "2021-03-16T17:07:06Z")

</div>

> val rqId = “MYLOADTEST\_” + Verification.randomAlpha(20)

val is a value, so it’s only computed once =\> you want a def (method)

def rqId = “MYLOADTEST\_” + Verification.randomAlpha(20)

---

<div class="post-metadata">

### Author: ![Richard\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Richard\_Livingstone](https://community.gatling.io/u/Richard_Livingstone)
#### Post date: [March 16, 2021, 10:13pm UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/3 "2021-03-16T22:13:04Z")

</div>

Fantastic, that is sort of what I need. There are two places I need this value though - one is to seed a verification hash function, the output of which goes into another form parameter, and the other is the actual form parameter itself above. Is there a clever way to use a def but to ensure for the same invocation somehow it returns a single value. Does that make sense? I can work round all of this but would rather not need to.

Thanks for the help so far though, always good to learn something new!

---

<div class="post-metadata">

### Author: ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)
#### Post date: [March 17, 2021, 10:49am UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/4 "2021-03-17T10:49:49Z")

</div>

If I understand, what you are seeking is to save the generated `rqId` for one virtual user.

So, you can save it in the `session`.

```auto
def generateRqId = "MYLOADTEST_" + Verification.randomAlpha(20) // Note I renamed this function to better show what happens =)

scenario("My test")
  .exec(session => session.set("rqId", generateRqId)) // save in session

  .exec(
    http("Payment123JS")
      .post("<snip my URL>")
      .formParam("requestId", "${rqId}") // simple usage here
      .formParam("language", "en")
<snip>
      .check([status.is](http://status.is)(200))
    )
    .pause(1)

```

If needed, you can save a new `rqId` whenever you want.

---

<div class="post-metadata">

### Author: ![Richard\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Richard\_Livingstone](https://community.gatling.io/u/Richard_Livingstone)
#### Post date: [March 17, 2021, 4:29pm UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/5 "2021-03-17T16:29:50Z")

</div>

Many thanks. I think this will do what I need. Scala is great - never used it before, I’ve done most of my development in Java, C++, C and JS to date.

---

<div class="post-metadata">

### Author: ![Richard\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Richard\_Livingstone](https://community.gatling.io/u/Richard_Livingstone)
#### Post date: [March 18, 2021, 9:24am UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/6 "2021-03-18T09:24:56Z")

</div>

Hmm - not quite right yet. My code is :

def generateRqId = “MYLOADTEST\_” + Verification.randomAlpha(20)

val scn = scenario(“RSL”)  
.exec(session =\> session.set(“rqId”, generateRqId))  
.exec(  
http(“MYLOAD”)  
.post(“myurl”)  
.formParam(“requestId”, “${rqId}”)  
.formParam(“verify”, Verification.processIntoValue(“DATASTARTrequestid=${rqId}|otherstuff=xyz”))  
.check(status.is(200))  
.check(substring(“seqNumber=”).exists)  
)  
.pause(1)

Unfortunately, although it passes the right value as the form param requestId, it passes the literal ${rqId} into the method Verification.processIntoValue rather than the session value. If I separate it into “DATASTARTrequestid=” + “${rqId}” + “|otherstuff=xyz”, the same. So the form param verify ends up incorrect. That’s what I was meaning by using the same value in two places.

Apologies if this gets posted twice, I posted and it seems to have vanished 🙂

---

<div class="post-metadata">

### Author: ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)
#### Post date: [March 18, 2021, 9:35am UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/7 "2021-03-18T09:35:50Z")

</div>

`Verification.processInfoValue` is your own method, I guess.  
And this is not aware of the session.

The code I provided use some scala magic to change `formParam("requestId", "${rqId}")` into `formParam("requestId", session => session.get("rqId"))` (in reality, there is something more complicated, but the idea is here).

So, in your case, you need to build your own value:

```auto
        .formParam("verify", Verification.processIntoValue("DATASTARTrequestid=${rqId}|otherstuff=xyz"))

```

to something like:

```auto
        .formParam("verify", Verification.processIntoValue(session => "DATASTARTrequestid=" + session("rqId").as[String] +|otherstuff=xyz"))

```

Source: [https://gatling.io/docs/current/session/session\_api/](https://gatling.io/docs/current/session/session_api/)

---

<div class="post-metadata">

### Author: ![Richard\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@Richard\_Livingstone](https://community.gatling.io/u/Richard_Livingstone)
#### Post date: [March 18, 2021, 10:55am UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/8 "2021-03-18T10:55:51Z")

</div>

Cheers - I had to change to this:

.formParam(“verify”, session =\> Verification.getHash(“DATASTARTrequestid=” + session(“rqId”).as[String] +…

but it now does exactly what I need. Many thanks for your help. Impressed with Gatling - first time I’ve used it, easy to use and gather results.

---

<div class="post-metadata">

### Author: ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)
#### Post date: [March 18, 2021, 11:05am UTC](https://community.gatling.io/t/unique-post-param-value-for-every-call/6019/9 "2021-03-18T11:05:02Z")

</div>

You’re right.

I edited the line directly in the mail and didn’t put the `session =>` in the good parentheses.

Good to know it works for you ^^

If your usage needs metrics history, run comparison or more than one machine to run the load test, consider using FrontLine to support us ^^
