Postman env: set only current value with Postman API

I would love to streamline the on-boarding process for new users on my team.

Requirement: We keep all environment variables in the current value column to avoid syncing the values to the cloud and protect sensitive information.

What we currently do: The new dev manually creates 5 different environments, then switches to each one and runs some scripts given to them by a team mate in the “pre-request script” tab. This populates all variables for that environment. Then they repeat this process for each environment.

What I want to do: Use the Postman Api to create a collection that makes this process simpler. Ideally one request that creates many collections and populates ONLY the current values.

Is there a way to set variables in environments that are not selected?
Can you set ONLY the current value with the API?

I’m open to suggestions.

Hey @KrisBr4,

Welcome to the community! :star2:

Creating those different environment files with placeholder variable names should be easy enough using the Create Environment endpoint on the Postman API. You could create a Collection and run that in the Collection Runner or with Newman.

POST https://api.getpostman.com/environments?apikey=<yourAPIKey>

The Request Body could be something simple like:

{
    "environment": {
        "name": "{{envName}}",
		"values": [
			{
				"key": "{{varOne}}",
				"value": "",
				"enabled": true
			},
			{
				"key": "{{varTwo}}",
				"value": "",
				"enabled": true
			}
		]
    }
}

You can then create a Data File containing the different names and the Runner would iterate over those and fill in the variable placeholders in the request Body and create the Environments.

Something simple like this:

[
  {
    "envName": "Environment One",
    "varOne": "username",
    "varTwo": "password"
  },
  {
    "envName": "Environment Two",
    "varOne": "username",
    "varTwo": "password"
  },
  {
    "envName": "Environment Three",
    "varOne": "username",
    "varTwo": "password"
  }
]

I think you’re going to struggle to add only current values, using the Postman API though.

Those values are only supposed to be known locally so once you add these to a request, which calls the Postman API - Those values are no longer just known locally and are synced to the cloud.

1 Like

Still not able to update environment variables ‘current value’ with API. any updates solution on this ??

This wouldn’t populate just the current value, when using the Postman API.

Those values are only supposed to be known locally so once you add these to a request, which calls the Postman API - Those values are no longer just known locally and are synced to the cloud.

I developed an IDEA plugin and in my plugin, I can update requests or environment to Postman using Postman API.

When I change the environment value and then use Update Environment API to update the environment, then I run the request in Postman and this request will use the old environment value but not the updated one. So update environment API has no value even if the workspace is private.

So, is there any plan to develop an API that can update Current Value of environment

I very much doubt it, as the current value is not synced to the cloud or included if you export the environment to a json file to include in your code repository.

This is for a good reason, as this is where you store confidential information like tokens, client secrets and passwords and these shouldn’t be sycned to the Postman cloud or included in your code repository. These artefacts should be stored in a key vault or another secure location.

The idea is that you cut and paste these when working with them locally.

You would automate the process in your continuous integration tool when running the pipelines. One of the first steps in the pipeline would be to retreive these secrets and send them to the CI tool in the command line (so its only really automated at this point).