How to execute only failed requests in a collection

Hi,
I am new here.
Need help, as of how to rerun only the failed requests in a collection.
I tried to capture the requests with failed test results , by updating a counter and set it up as a environment variable.But that did not pan out well.

Can anyone help please?

@sgextron

How many requests are in a collection ?

Do you have a non-critical endpoint like a “ping” ? We have a ping endpoint the simply returns “Hello World”. If you have something like that, I would use that as the start off point for running any or all your requests in a collection.

You could create a JSON file that would have a list of your requests within the collection. This JSON file would be the “iteration” input during a “collection run”.

[
    { "runType" : " test" , "requestName" : "Request A to do something" },
    { "runType" : " skip" , "requestName" : "Request B to do something" },
    { "runType" : " test" , "requestName" : "Request C to do something" }
]

The “ping” endpoint would be the first in the series of requests and it’s “test” script would have …

    If ( data.runType == 'test' ) {
        postman.setNextRequest(data.requestName);
    }
    else {
        postman.setNextRequest(null); //stop this iteration and start the next iteration
    }

Each of the requests, listed in the collection, after the “ping” request, such as … “Request A to do something” … would have somewhere in it’s “test” script …

    postman.setNextRequest(null);  //stop this iteration and start the next iteration 

This would end the iteration after the request had finished, loop back to the “ping” endpoint which would then get the next “requestName” to run and continue until the last iteration.

Once you have established all the failing requests, you could edit/adjust the “runType” setting in the JSON file to “skip” your passing tests and only run your failing tests.

Not sure if this is exactly what you were looking for, but hope it is.

@dhoyt Hi sir,
Have used ur code –

[
{“runType” : 401 && 500, “requestName” : “{{realAPIUrl}}/api/bot/InteractionManagement/SF001A”}
]
if(data.runType == 401 && 500){
postman.setNextRequest(“{{login}}/oauth2/v2.0/token”);
}
else{
postman.setNextRequest(null);
}
still not working… pls help me on this one – thanks in advance sir