Reputation: 31
I want to make a postman request that returns a list of IDs. The returned list can contain 1 or multiple IDs. In tests section i want to use these returned IDs to make new requests. Is it possible to send requests from tests section in for loop and check their returned data BEFORE sending another request?
I tried using simple for loop and pm.sendRequest but due to async this did not work.
Is this possible using Postman?
Upvotes: 0
Views: 1341
Reputation: 5917
You can achieve that by using postman.setNextRequest("request_name")
For example:
Tests
Get the ids and save ids to environmentpm.environment.set("ids", JSON.stringify(pm.response.json().ids));
Tab Pre-req
let ids = JSON.parse(pm.environment.get("ids"));
if(ids.length > 0){
let id = ids.shift();
pm.environment.set("ids", JSON.stringify(ids));
pm.variables.set("id", id);
}
Tab Tests
let ids = JSON.parse(pm.environment.get("ids"));
if(ids.length > 0){
postman.setNextRequest("Req2");
}
Result:
Upvotes: 2