I have created multiple environments, I would like to access the variables in a specific environment based on the response body of the request in the current environment.
Is this possible?
I have had no response so my assumption that is not currently possible. Logged feature request:
First, thank you for opening a feature-request. It helps provide visibility and gauge user interest. So just wanted to say we appreciate your feedback and involvement!
Regarding your inquiry, you’re right as far as I know there isn’t a way to do so; however, you should be able to accomplish by making use of pm.sendRequest and the Postman API. So you’d use pm.sendRequest to fetch the relevant Environment and save it to a local variable in your script and use it accordingly.
Thanks Sabri , this suggestion is certainly plausible, Are there any security considerations when using this method ? My “project” seems to be public ?
As long as you’re not exposing your API key. You’re forming the request in your scripts to with pm.sendRequest and fetching the Environment from the Postman API. Additionally, given you’re setting the relevant value from your Environment to a local variable, it doesn’t persist between sessions. As mentioned here: Store and reuse values using variables | Postman Learning Center
For example, if you need to process a temporary test value for a single request or collection run locally, and don’t want the value to sync with your team or remain available when the request / collection has finished running, you can use a local variable.
This solves my requirement in the short term, with some workarounds as I cannot connect to the Postman API while connected to the Customer’s network.
I would still appreciate it if the Postman team considers making this feature available locally. Thanks for all your input.