Skip request in pre-request script

Is it possible to skip the request if a variable matches a criteria in the pre-request script?
So let´s say if variable XY is 123 skip this request, otherwise send the request.

Thanks,
Philipp

1 Like

Hi @ger0001p,

You can build request workflows based on conditionals using postman.setNextRequest() in the pre-request scripts as explained here: postman.setNextRequest() ignore other requests in collections.

More useful links:

I don’t think @suraj.purohit’s answer works for his question. He is asking if there is a way in a pre-request script to cause that request to never even get executed. setNextRequest says that it will just say what the next request to execute would be from the previous test script and that even if setNextRequest is set in the pre-request, then the request and test would still get executed.

Here would be a valid scenario.

pre-Call1 (empty)
request-Call1 (execute GET)
test-Call1 (set variable “xy” from response)

pre-Call2 (empty)
request-Call2 (execute GET)
test-Call2 (some tests)

pre-Call3 (check if “xy” === “123” skip request-Call3)

pre-Call4 (empty)
request-Call4 (execute GET)
test-Call4 (some tests)

@ger0001p I think the way you would have to do it is in the previous test you would do a setNextRequest to the test after the one you want to skip. I think that is the route I am going to go since I have to either make a request or not depending 8 requests down the chain based on the response

1 Like

Hi @ger0001p https://github.com/postmanlabs/postman-app-support/issues/8929 this post would be of use to you.

This topic is in development phase.

1 Like

hope to have soon, it will be a good feature