I am looking for certain “key”:“value” pair in JSON response. This key-value appears after repeating 3-5 same API requests. What needs to be done to make repeated API calls to get this key-value pair?
@vn0gdpo This should be easy to solve using something like Postman Workflow and a conditional check.
In the Tests
tab of the request.
You would add in a a conditional check to validate of the key value is false, if so then you would set the next request to be the same call. This would continue until the condition is true
and then execution would continue as normal.
(reminder that this would only work when executing a collection and not a single request.)
So here is an example. If I was checking the value of status
in my response. If it was processing
, then call the same call again until it’s something other than processing
, for example complete
.
var response = pm.response.json();
if (response.status === "processing"){
postman.setNextRequest("Check Status");
}
Here is some more information on Workflows:
https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/#advanced-workflow
That’s the thing. I want to use it in a single request too.
@vn0gdpo In that case you may be able to do something like this …
var response = pm.response.json();
if (response.status === "processing"){
pm.sendRequest("https://myurlthatiwant.org", function (err, response){});
}