Retrieving value from a response and then reusing it in another request

Hello, I’m using gatling 3.7.6 along with Java 11. I am able to execute single API tests but now stuck where I need to execute multiple requests one after another using the keys from previous request response. For example I’m executing an auth. request and using the token in the subsequent requests as shown below:
First reqs:


2nd reqs:
.header(“Authorization”," Bearer "+ session.getString(auth_token))

Let me what is wrong here, quick response will be appreciate.


You can check this tooic:

Hi @neo_81,

Welcome aboard!

First, you should upgrade, latest version is 3.9.5 and this forum only support the latest version.

About your code, I bet that your “2nd reqs” doesn’t compile. There is no session out of nowhere.

You should go with a lambda (you mention Java 11, I guess you use the Gatling Java DSL).

.header(“Authorization”, session -> { return "Bearer " + session.getString(auth_token); })

Does that helps?


Thanks for replying and giving hint, made it work plus found another way. See below:
first way
.header(“Authorization”,"Bearer "+ “#{auth_token}”)
2nd way
.header(“Authorization”, session → { return "Bearer " + session.getString(“auth_token”); })

.header(“Authorization”,“Bearer #{auth_token}”)



Lol, yes. Thanks for pointing that out.