Only want to run POST APIs if the environment is QA not PROD.
Can we check this in pre-script, if it’s PROD, the pre-script just exit without continue ?
Only want to run POST APIs if the environment is QA not PROD.
Can we check this in pre-script, if it’s PROD, the pre-script just exit without continue ?
How about this pseudo code ?
if (pm.environment.name === “Prod”) {
console.log(“Don’t run”);
throw new Error(“No POST APIs for Prod”);
}
~
Hey @ningji
Welcome to the Postman Community!
The script would throw an error under that conditional statement and stop the run, stating that there was an error evaluating the pre-request script.
if (pm.environment.name === "PROD") {
console.log("Don’t run");
throw new Error("No POST APIs for Prod");
};
Hi Danny,
Thx for your reply.
A follow up question is, if i have a collection of 2 APIs.
The 1st API will have a pre-script as above.
The 2nd has no pre-script.
If i run this collection in PROD, will the 2nd API run ?
Hey @ningji,
Have you tried this out, maybe in a non PROD environment, to test what happens?
I find the best way to see if something works or not is to try it out
I only know part of what you’re trying to do, I can’t see the full picture - If you don’t want any requests to run in PROD, you can add this to the Collection level pre-request to error out at the first request in the Collection.