Editing Shared Environments & Environment Variables

Please Note: Unfortunately, Team Members that are already subscribed to the environment will NOT have their environments updated. They’ll have to delete/re-subscribe to environment until the Postman team make this feature possible.

This tutorial is to update a shared environment that’s been used in your CI. (TeamCity, Jenkins etc.)

Hi,
This was a question that was asked quite a bit in the Postman Slack and it was something that I always found painful - “How do I edit shared environments/environment variables with my team?”

Unfortunately this isn’t supported through the UI…yet!
Please +1 the Feature Requests int the Postman Git to show the Postman Team this is something you want :slightly_smiling_face:

So, is there no way to do this at all through Postman?
Yes, it’s a little cumbersome but it works for me with my shared environments in TeamCity and other Postman Users have confirmed it working.

Get to it already, how do I do this?
OK! Let’s assume we have envionment shared with a team.
Using the Postman PRO API, use the GET All Environments request (you’ll need to use your Postman Pro API Key which is unique to you)

GET https://api.getpostman.com/environments

Remember to use the Postman Pro API Key as a Header.

In the above request you’ll see all your environments, some shared - some not shared.
Environments that are shared have “.template”. in the “name” field.
image

Take note of the value of the “uid” field.
In the GET Single Environment request pass in the “uid” as a path parameter

GET https://api.getpostman.com/environments/{{environmentUID}}

Copy the entire response body returned.

Using the PUT Edit Environment request, paste the copied response into the Request Body as raw JSON.

PUT https://api.getpostman.com/environments/{{environmentUID}}

Make sure you select JSON(application/json) from the dropdown above the body.

image

In the request body, edit/delete/add objects inside the ‘values’ array.
Each object will be an environment variable:

{
    "environment": {
        "id": "26cce2d3-2d24-2efe-c168-7312ca87f69c",
        "name": "KATA ENV.template",
        "values": [
            {
                "key": "exampleURL",
                "value": "https://www.google.com",
                "type": "text",
                "enabled": true
            },
            {
                "key": "myNewVariable",
                "value": "someTextGoesHere",
                "type": "text",
                "enabled": true
            }
        ]
    }
}

Make sure not to change the value of the “id” field.
If you submit the request you should get a 200 response code and the shared environment should be successfully updated :slight_smile:

In this case, in my shared environment ‘KATA ENV’, I added a new environment variable named ‘myNewVariable’ which has a value of ‘someTextGoesHere’

Assuming there’s a Newman test collection in our CI (In my case, TeamCity) that’s using this shared environment, the shared collection will now have the updated values/variables.

Hopefully there’s some value in this for you guys until this feature is properly supported through the UI.

Feel free to like this post so other users find it :smiley:

4 Likes

Shared environments are now available in Postman 6.0 :confetti_ball: