Need a Pre-request-script that acts like this: if some value === null then request its not sent, else request its sent

As mention at the tittle
Need a Pre-request-script that acts like this: if some variable === null then request its not sent, else request its send.

Context: For this API, DELETE request only applies if “variable” === “something” therefore when “Variable === null” tests fails and my automation stops.

Any ideas?
Thanks in advanced.
Cheers.

Hi @ibragroupsantander

I think you would have to do this in the ‘test’ tab of the first call so that you could query the HTTP response… Assuming that the first call is a “create” call, the “variable” would only be set to “something” after the first HTTP request was successfully executed right?


You could look at something like;

if (some variable === null) {
postman.setNextRequest(null);
}else{
postman.setNextRequest("Delete_Request");
}

Alternitively if you have to run this from a pre-req script and hardcode a variable then you would likely need to use pm.sendRequest()

More info on this can be found here:

First thank you for the answer. Problem is when value === null then “null” is not readable therefore can´t be stored in a variable. See attached captures.


what does your response look like?
I don’t think you need .value on line 8 but hard to advise without seeing the actual response.