# Load test only the second API , after getting data from first API

**URL:** <https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432>\
**Category:** Gatling (Open-Source)\
**Created:** [November 9, 2023, 10:09am UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432 "2023-11-09T10:09:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [November 9, 2023, 10:09am UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432/1 "2023-11-09T10:09:24Z")

</div>

> [@Cannot pass the response value of first api request to the second api request](https://community.gatling.io/t/cannot-pass-the-response-value-of-first-api-request-to-the-second-api-request/8031):
>
> I have a gatling code below where I want the value of the listingid in the response of the first api be passed to the request of the second api. However, only the first api is successful. Kindly help. class ClassifiedGenerator extends Simulation{ // protocol val httpProtocol: HttpProtocolBuilder = http .baseUrl("https://url.com") // scenario //first api val createlistingidscn: ScenarioBuilder = scenario("create listingid") .exec( http("create listingid") .post(…

I have a similar case to this.  
I need to get data from first API and pass that data to second API. I have created scenario with chaining these 2 api’s. When I executed simulation , both the API’s gets executed N number of times.

Instead I want to execute the first API only once and get the data and load test only the second API. How can I achieve this

---

<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:** [November 9, 2023, 10:17am UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432/2 "2023-11-09T10:17:48Z")

</div>

Hi @partheeban,

If I understand correctly your requirements, you want to fetch the initial data once then use that with several virtual users.

If fetching the initial data is fast enough, you may want to use a classic client during the Simulation initialization phase to fetch the data.

Otherwise, you may use a global variable, a first scenario (with only one user) will fetch the data and store id in the global variable [andThen](https://gatling.io/docs/gatling/reference/current/core/injection/#sequential-scenarios) the second scenario will get this global variable to compute the data for the real load test.

Does that help?

Cheers!

---

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [November 9, 2023, 2:50pm UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432/3 "2023-11-09T14:50:28Z")

</div>

Thank you very much. I am able to implement this.

---

<div class="post-metadata">

**Author:** ![GeMi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/gemi/32/939_2.png) [@GeMi](https://community.gatling.io/u/GeMi)\
**Post date:** [November 9, 2023, 4:23pm UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432/4 "2023-11-09T16:23:17Z")

</div>

You can look in solution in below topic, there you have this kind of request what you need.  
[https://community.gatling.io/t/token-refresh-java-example/7935](https://community.gatling.io/t/token-refresh-java-example/7935)

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [December 9, 2023, 4:23pm UTC](https://community.gatling.io/t/load-test-only-the-second-api-after-getting-data-from-first-api/8432/5 "2023-12-09T16:23:58Z")

</div>

Closed on December 9, 2023, 4:23pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
