# Capture JSON Response and pass to another Request

**URL:** <https://community.gatling.io/t/capture-json-response-and-pass-to-another-request/5705>\
**Category:** Gatling (Open-Source)\
**Created:** [July 8, 2020, 2:26am UTC](https://community.gatling.io/t/capture-json-response-and-pass-to-another-request/5705 "2020-07-08T02:26:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prithav\_Kumar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Prithav\_Kumar](https://community.gatling.io/u/Prithav_Kumar)\
**Post date:** [July 8, 2020, 2:26am UTC](https://community.gatling.io/t/capture-json-response-and-pass-to-another-request/5705/1 "2020-07-08T02:26:38Z")

</div>

Hi,

I am able to capture the JSON Response from the previous Request but not able to pass the particular value in next Request. Here is the example-

http(“request\_100”)  
.post(“/cometd/handshake”)  
.headers(headers\_100)  
.body(StringBody(“”“[{“id”:“1”,“version”:“1.0”,“minimumVersion”:“1.0”,“channel”:”/meta/handshake",“supportedConnectionTypes”:[“long-polling”,“callback-polling”],“advice”:{“timeout”:60000,“interval”:0}}]“”“)).asJson  
.check(jsonPath(”$…clientId").find.saveAs(“client1”)),

http(“request\_101”)  
.post(“/cometd/connect”)  
.headers(headers\_100)  
.body(StringBody(“”“[{“id”:“2”,“channel”:”/meta/connect",“connectionType”:“long-polling”,“advice”:{“timeout”:0},“clientId”:“${client1}”}]“”“)).asJson  
.check(jsonPath(”$…\*").find.saveAs(“resp1”)),

.exec ( session =\> {  
println(session(“client1”).as[String])  
println(session(“resp1”).as[String])  
session  
})

The Response from request\_100 is -

[{“minimumVersion”:“1.0”,“clientId”:“f1rm2vubs7q4h61iot8ghn6ai9u”,“supportedConnectionTypes”:[“long-polling”],“channel”:“/meta/handshake”,“id”:“1”,“version”:“1.0”,“successful”:true}]

clientId is captured from the previous request but while passing the clientId using client1, I am seeing the below error to build the request\_101. Here is the error-

---- Errors --------------------------------------------------------------------

> request\_101: Failed to build request: No attribute named ‘clie 1 (11.11%)  
> nt1’ is defined

17:03:31.917 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-29’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘resp1’ is defined’, forwarding to the next one

---

<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:** [July 8, 2020, 5:36am UTC](https://community.gatling.io/t/capture-json-response-and-pass-to-another-request/5705/2 "2020-07-08T05:36:20Z")

</div>

It looks like those requests are wrapped in a resources group, meaning they are executed in parallel, not sequentially, so there’s no way request\_101 can be built based on request\_100’s result. You must execute them sequentially in sequential distinct exec blocks.
