postman-app-support icon indicating copy to clipboard operation
postman-app-support copied to clipboard

Set existing environment as pre-req script, or link "default" environment with collection

Open Balky79 opened this issue 2 years ago • 15 comments

Is there an existing request for this feature?

  • [X] I have searched the existing issues for this feature request and I know that duplicates will be closed

Is your feature request related to a problem?

I have a fair amount of collections and environments, and drop down selector works fine, but. In most of the cases my first call will fail, as I'll forget to change the environment.

Describe the solution you'd like

I'd like to have is chance to programmatically set "default" environment per collection, or to be able to link it in the collection settings.

So, whenever I click on collection "C", environment "C" would be pre-selected as default. Then if I need a different one, I'll again go to drop down selector.

Describe alternatives you've considered

No response

Additional context

No response

Balky79 avatar Jul 01 '22 16:07 Balky79

I came here looking for a solution and found this. I would like to share a design idea for this with backward compatibility considered. 1- collections to have a new tab to link global environments to restrict environment options for this collection 2- marking one of these collection environments as a default (or the first one added to the list will be the default) 3- if no environments were specified for the collection, all environments are available to be selected as the current behavior. 4- [this is an extra one but would be nice to have] coloring the environments that have missing variables defined than the others in the same collection list (kind of diff check)

This restricts environments per collection if needed while keeping the current functionality available. Environments are clearly not usable for every collection in the list so this solves the problem and reduces the list of which we choose the environment on change for that collection. Marking the default environment is very helpful on quick switching between different collections and requests.

CME64 avatar Jul 05 '22 11:07 CME64

Yes from me too. At the very least, store the last choice of environment in a cookie or local storage so that when I refresh the page, it is chosen again automatically. Right now it defaults to No environment.

Or: When I click any action that could potentially require an environment (like running a request that has unresolved variables), show a prompt:

Your request has unresolved variables and you've not selected an environment. Select an environment to resolve them with:

[ filter search box ] (text box) [ Dev ] [ Prod ] [ Local ] etc. (buttons for most recently used) [ Cancel request ] (button)

Anything to improve the user experience would be a welcome change.

ADTC avatar Sep 15 '23 04:09 ADTC

I was happy with collection variables in this scope of problems, but recently Postman effectively ruined these collection variables by demanding to publish all of them to their cloud. The only way to keep secret secret is to try using environment «secret» variables.

And here the problem of switching to correct environment comes into full power.

So far I am using script at least in auth-request of collection:

let environmentName = "my_project environment";
if(pm.environment.name !== environmentName) {
   throw new Error(environmentName + " required!");
}

But I hate to insert it into EVERY pre-req.

Maybe another solution could be «secret» collection variables?

exec228 avatar Oct 04 '23 12:10 exec228

With Scratchpad being discontinued, this is becoming somewhat irrelevant - I'm switching to selfmade python solution. Sadly.

On Wed, Oct 4, 2023 at 1:07 PM exec228 @.***> wrote:

I was happy with collection variables in this scope of problems, but recently Postman effectively ruined these collection variables by demanding to publish all of them to their cloud. The only way to keep secret secret is to try using environment «secret» variables.

And here the problem of switching to correct environment comes into full power.

So far I am using script at least in auth-request of collection:

let environmentName = "my_project environment"; if(pm.environment.name !== environmentName) { throw new Error(environmentName + " required!"); }

But I hate to insert it into EVERY pre-req.

Maybe another solution could be «secret» collection variables?

— Reply to this email directly, view it on GitHub https://github.com/postmanlabs/postman-app-support/issues/11055#issuecomment-1746742581, or unsubscribe https://github.com/notifications/unsubscribe-auth/AENMO3IKPVFE5KHRMJPAOH3X5VGO7AVCNFSM52NGFEX2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZUGY3TIMRVHAYQ . You are receiving this because you authored the thread.Message ID: @.***>

-- http://igor.stojakovic.net/ - Travel blog, Ireland, books, food and more! :) http://www.stojakovic.net - Mobile Apps, Webs and more!

Balky79 avatar Oct 04 '23 15:10 Balky79

But I hate to insert it into EVERY pre-req.

@exec228 If you put all your requests inside a collection, you can just set the pre-request script on the collection. It will run for every request inside the collection.

(You can organize the requests in folders inside the collection.)

ADTC avatar Oct 04 '23 16:10 ADTC

@ADTC Thank you! Good to know! The only wish left is to «switch to desired collection», instead of «rejecting other collections» 😀

exec228 avatar Oct 06 '23 05:10 exec228

@exec228 have you considered using Globals instead? It looks like you always want to choose the same environment. Then it should just be in Globals, rather than a named environment.

Global variables for a workspace are a set of variables that are always available within the scope of that workspace. They can be viewed and edited by anyone in that workspace. Learn more about globals.

I don't know why Postman removed the ability to set secret variables in collections. It would be incredibly useful to set them everywhere. Why are collections exempted? A strange decision.

BTW, I'm not sure what you mean by "demanding to publish all of them to their cloud" and "The only way to keep secret secret is to try using environment «secret» variables" because even secret variables are published to the cloud. The "secret" setting is merely a visual masking of the value on-screen.

ADTC avatar Oct 09 '23 14:10 ADTC

@ADTC Thank you! However, having multiple collections, I will immediately have a total mess with logins and similar details.

My history is this:

  1. Potzman undeniably annoyed me with upgrades, but I followed them.
  2. Potzman threatened to erase all my work locally, unless I publish them on their cloud.
  3. Potzman officially instructed me to keep secret data in environments, rather than collections, to save them from publishing.
  4. Potzman cynically published all my secrets.

How nice!

exec228 avatar Oct 10 '23 05:10 exec228

Setting default environments per collection would be handy. I bounce between collections so eliminating the step of switching environments each time would be handy.

Mrjwm avatar Jan 15 '24 22:01 Mrjwm

I'd like to see the feature to select an environment for collections so that I won't need to select an environment again every time I reopen the collection.

ivanprof avatar Jan 18 '24 15:01 ivanprof

I would like to have this too!

Harm10 avatar Apr 25 '24 15:04 Harm10

Hey folks, We are working on a feature where you can pin specific environments to your collections. This feature will be releasing later this month. We are exploring the option of choosing one of the pinned environments as default image

giridharvc7 avatar Apr 26 '24 07:04 giridharvc7

Excellent news, sadly - I'll never use it.

Since you forcefully moved scratchpad and moved everything to the cloud, I had to explore different tools, and defaulted back to curls and scripting.

We had a good run, you can keep the feature :D

Balky79 avatar Apr 26 '24 12:04 Balky79

Pinning an environment to the collection would also be of use when using Postman CLI!

Harm10 avatar Apr 26 '24 18:04 Harm10

Hey folks, We are working on a feature where you can pin specific environments to your collections. This feature will be releasing later this month. We are exploring the option of choosing one of the pinned environments as default image

This would be very helpful!

bobpozun avatar May 02 '24 13:05 bobpozun

The latest version has the option to pin an environment which is useful. But exported collections do not save this option so Postman CLI has no advantage of it............... :-(

Will this be added in the future?

Harm10 avatar May 06 '24 11:05 Harm10

You can pin more than one environment. It doesn't set a default though, but if you have a long list of environments, you can pin the ones most relevant to the collection.

If you only have a handful of environments though, the pinning feature seems pretty useless.

ADTC avatar May 06 '24 20:05 ADTC