> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Replace an environment's data

PUT https://api.getpostman.com/environments/{environmentId}
Content-Type: application/json

Replaces all the contents of an environment with the given information.

**Note:**

- The request body size cannot exceed the maximum allowed size of 30MB.
- If you receive an HTTP `411 Length Required` error response, manually pass the `Content-Length` header and its value in the request header.


Reference: https://learning.postman.com/api-docs/api-reference/environments/put-environment

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /environments/{environmentId}:
    put:
      operationId: putEnvironment
      summary: Replace an environment's data
      description: >
        Replaces all the contents of an environment with the given information.


        **Note:**


        - The request body size cannot exceed the maximum allowed size of 30MB.

        - If you receive an HTTP `411 Length Required` error response, manually
        pass the `Content-Length` header and its value in the request header.
      tags:
        - environments
      parameters:
        - name: environmentId
          in: path
          description: The environment's ID.
          required: true
          schema:
            $ref: '#/components/schemas/environmentId'
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/putEnvironmentResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PutEnvironmentRequestBadRequestError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PutEnvironmentRequestUnauthorizedError'
        '411':
          description: Length Required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetailStatusInstance'
        '413':
          description: Payload Too Large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetailStatusInstance'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PutEnvironmentRequestInternalServerError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/putEnvironment'
servers:
  - url: https://api.getpostman.com
    description: https://api.getpostman.com
  - url: https://api.eu.postman.com
    description: https://api.eu.postman.com
components:
  schemas:
    environmentId:
      type: string
      title: environmentId
    EnvironmentVariablesType:
      type: string
      enum:
        - secret
        - default
      description: |
        The variable's type:
        - `secret` — The variable value is masked.
        - `default` — The variable value is visible in plain text.
      title: EnvironmentVariablesType
    environmentVariables:
      type: object
      properties:
        enabled:
          type: boolean
          description: If true, the variable is enabled.
        key:
          type: string
          description: The variable's name.
        value:
          type: string
          description: The variable's value.
        type:
          $ref: '#/components/schemas/EnvironmentVariablesType'
          description: |
            The variable's type:
            - `secret` — The variable value is masked.
            - `default` — The variable value is visible in plain text.
        description:
          type: string
          description: The variable's description.
      description: Information about the environment's variables.
      title: environmentVariables
    PutEnvironmentEnvironment:
      type: object
      properties:
        name:
          type: string
          description: The environment's name.
        values:
          type: array
          items:
            $ref: '#/components/schemas/environmentVariables'
          description: Information about the environment's variables.
      description: Information about the environment.
      title: PutEnvironmentEnvironment
    putEnvironment:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/PutEnvironmentEnvironment'
          description: Information about the environment.
      title: putEnvironment
    PutEnvironmentResponseEnvironment:
      type: object
      properties:
        id:
          type: string
          description: The environment's ID.
        name:
          type: string
          description: The environment's name.
        uid:
          type: string
          format: uid
          description: The environment's unique ID.
      description: Information about the environment.
      title: PutEnvironmentResponseEnvironment
    putEnvironmentResponse:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/PutEnvironmentResponseEnvironment'
          description: Information about the environment.
      title: putEnvironmentResponse
    CommonErrorNameMessageDetailsErrorDetails:
      oneOf:
        - type: object
          additionalProperties:
            description: Any type
        - type: array
          items:
            type: string
      description: Information about the error.
      title: CommonErrorNameMessageDetailsErrorDetails
    CommonErrorNameMessageDetailsError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
        details:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsErrorDetails'
          description: Information about the error.
      title: CommonErrorNameMessageDetailsError
    commonErrorNameMessageDetails:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageDetailsError'
      title: commonErrorNameMessageDetails
    CommonErrorNameMessageError:
      type: object
      properties:
        name:
          type: string
          description: The error name.
        message:
          type: string
          description: The error message.
      description: Information about the error.
      title: CommonErrorNameMessageError
    commonErrorNameMessage:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/CommonErrorNameMessageError'
          description: Information about the error.
      title: commonErrorNameMessage
    PutEnvironmentRequestBadRequestError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorNameMessageDetails'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: PutEnvironmentRequestBadRequestError
    CommonErrorTypeTitleDetailStatusType:
      oneOf:
        - type: string
          format: uri-reference
        - type: string
      title: CommonErrorTypeTitleDetailStatusType
    commonErrorTypeTitleDetailStatus:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailStatusType'
        title:
          type: string
          description: A short summary of the problem.
        detail:
          type: string
          description: Information about the error.
        status:
          type: integer
          description: The error's HTTP status code.
      title: commonErrorTypeTitleDetailStatus
    PutEnvironmentRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: PutEnvironmentRequestUnauthorizedError
    commonErrorTypeTitleDetailStatusInstance:
      type: object
      properties:
        type:
          type: string
          format: uri-reference
          description: >-
            The [URI reference](https://www.rfc-editor.org/rfc/rfc3986) that
            identifies the type of problem.
        title:
          type: string
          description: A short summary of the problem.
        detail:
          type: string
          description: An explanation about the problem.
        status:
          type: integer
          description: The HTTP status code generated by the origin server.
        instance:
          type: string
          description: >-
            The URI reference that identifies the specific occurrence of the
            problem.
      title: commonErrorTypeTitleDetailStatusInstance
    CommonErrorTypeTitleDetailDetail:
      oneOf:
        - type: string
        - type: object
          additionalProperties:
            description: Any type
      description: Information about the error.
      title: CommonErrorTypeTitleDetailDetail
    commonErrorTypeTitleDetail:
      type: object
      properties:
        type:
          type: string
          description: The type of error.
        title:
          type: string
          description: A short summary of the problem.
        detail:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailDetail'
          description: Information about the error.
      title: commonErrorTypeTitleDetail
    PutEnvironmentRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: PutEnvironmentRequestInternalServerError
  securitySchemes:
    PostmanApiKey:
      type: apiKey
      in: header
      name: x-api-key
    scimApiKey:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        A valid [SCIM API
        key](https://learning.postman.com/docs/administration/scim-provisioning/scim-provisioning-overview/#generating-scim-api-key)
        for calls to SCIM endpoints.
    basicAuth:
      type: http
      scheme: basic

```

## Examples

### Successful Response



**Request**

```json
undefined
```

**Response**

```json
{
  "environment": {
    "id": "5daabc50-8451-43f6-922d-96b403b4f28e",
    "name": "Test A Environment",
    "uid": "12345678-5daabc50-8451-43f6-922d-96b403b4f28e"
  }
}
```

**SDK Code**

```python Successful Response
import requests

url = "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, headers=headers)

print(response.json())
```

```javascript Successful Response
const url = 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: undefined
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Successful Response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

	req, _ := http.NewRequest("PUT", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Successful Response
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Successful Response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Successful Response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Successful Response
using RestSharp;

var client = new RestClient("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Successful Response
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Replace Environment Data



**Request**

```json
{
  "environment": {
    "name": "Test A Environment",
    "values": [
      {
        "enabled": true,
        "key": "collectionId",
        "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
        "type": "default",
        "description": "The collection's ID."
      }
    ]
  }
}
```

**Response**

```json
{
  "environment": {
    "id": "5daabc50-8451-43f6-922d-96b403b4f28e",
    "name": "Test A Environment",
    "uid": "12345678-5daabc50-8451-43f6-922d-96b403b4f28e"
  }
}
```

**SDK Code**

```python Replace Environment Data
import requests

url = "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

payload = { "environment": {
        "name": "Test A Environment",
        "values": [
            {
                "enabled": True,
                "key": "collectionId",
                "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
                "type": "default",
                "description": "The collection's ID."
            }
        ]
    } }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript Replace Environment Data
const url = 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"environment":{"name":"Test A Environment","values":[{"enabled":true,"key":"collectionId","value":"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2","type":"default","description":"The collection\'s ID."}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Replace Environment Data
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

	payload := strings.NewReader("{\n  \"environment\": {\n    \"name\": \"Test A Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Replace Environment Data
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"environment\": {\n    \"name\": \"Test A Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Replace Environment Data
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"environment\": {\n    \"name\": \"Test A Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      }\n    ]\n  }\n}")
  .asString();
```

```php Replace Environment Data
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e', [
  'body' => '{
  "environment": {
    "name": "Test A Environment",
    "values": [
      {
        "enabled": true,
        "key": "collectionId",
        "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
        "type": "default",
        "description": "The collection\'s ID."
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Replace Environment Data
using RestSharp;

var client = new RestClient("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"environment\": {\n    \"name\": \"Test A Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Replace Environment Data
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["environment": [
    "name": "Test A Environment",
    "values": [
      [
        "enabled": true,
        "key": "collectionId",
        "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
        "type": "default",
        "description": "The collection's ID."
      ]
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Remove Variables



**Request**

```json
{
  "environment": {
    "values": []
  }
}
```

**Response**

```json
{
  "environment": {
    "id": "5daabc50-8451-43f6-922d-96b403b4f28e",
    "name": "Test A Environment",
    "uid": "12345678-5daabc50-8451-43f6-922d-96b403b4f28e"
  }
}
```

**SDK Code**

```python Remove Variables
import requests

url = "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

payload = { "environment": { "values": [] } }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript Remove Variables
const url = 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"environment":{"values":[]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Remove Variables
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e"

	payload := strings.NewReader("{\n  \"environment\": {\n    \"values\": []\n  }\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Remove Variables
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"environment\": {\n    \"values\": []\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Remove Variables
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"environment\": {\n    \"values\": []\n  }\n}")
  .asString();
```

```php Remove Variables
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e', [
  'body' => '{
  "environment": {
    "values": []
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Remove Variables
using RestSharp;

var client = new RestClient("https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"environment\": {\n    \"values\": []\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Remove Variables
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["environment": ["values": []]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/environments/5daabc50-8451-43f6-922d-96b403b4f28e")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```