How to integrate precautions with methods that target the production environment?

We’ve used Postman for about two years now, but only recently diving into the bigger features, such as variables and environments. Using environments, it’s much easier to re-use the same method for each environment (OTAP). However, with great powers, come great responsibility. Having that POST method and created a PRODUCTION environment might result in people being people, firing a post-request to production, that should’ve been the TEST environment.

What measures can be taken to prevent or alert the user that he/she is targeting a production environment?

I wouldn’t mind getting a “Hey, you are targeting the Production environment. Do you want to continue?”.

Hey @sjeefr,

Welcome to the community! :wave:

I’m sure there are other ways and techniques that could be used but off the top of my head and something very basic is this:

if(pm.request.method === "POST" && === "PRODUCTION") {
    // Set the URL to something else to stop POSTing to Production
    pm.request.url = ""
    // If using the runner, this will stop the Collection Run

If you add this to the Pre-request Script, it will check if the method is POST and the environment selected is PRODUCTION - If true, it will change the request URL so something else (I’ve chosen but it could be anything else) Also, if you’re using the Runner, it will stop any subsequent requests from being sent.

This is just a basic suggestion and it will have its own set of context problems but worth checking out.

1 Like

Hey Danny! Thanks for the suggestion. Am I wrong that this prevents the production environment at all? I mean, how would I bypass that redirect when I am aware I’m using production and want to continue?

It’s just a simple method to stop someone from posting a request to a production environment, selecting say the “TEST” environment would allow folks to continue with what they are doing.

It’s more of a suggestion than any kind of permanent solution :grin: I’m unaware of your full context or the way that your Collections are structured.

There currently isn’t a ‘prompt’ or ‘alert’ in the app that acts as a pre step confirmation to check that you’re OK with using that environment.

1 Like