0

I want to execute 3 requests (api1, api2 and api3) one after the other. I want to make api3 request dependent on values(type:int) of api1 and api2.

In api1 request test body:

var data = pm.response.json();
var count1 = data.length;

In api2 request test body:

var data = pm.response.json();
var count2 = data.length;
if(count1 == 0 && count2 == 0){
    postman.setNextRequest(null);
}

Doing this, it throws a "ReferenceError: count1 is not defined" after firing the api2 request.

I don't want to execute the request api3 if both the count values (count1 and count2) are 0. Please help!

  • Does this answer your question? [Are global variables thread safe in flask? How do I share data between requests?](https://stackoverflow.com/questions/32815451/are-global-variables-thread-safe-in-flask-how-do-i-share-data-between-requests) – Shane Richards Sep 02 '20 at 13:44
  • Nope.. I need the syntax to use variable from one request into the other request in the postman app. – Fetch Roast Sep 02 '20 at 14:17

1 Answers1

4

In the test of the api1 request, you need to store the value of count1 in an environment variable: pm.environment.set("count1", count1));

Then use that environment variable in the test of api2: count1 = pm.environment.get("count1");

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37