> 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.

# Create an environment

POST https://api.getpostman.com/environments
Content-Type: application/json

Creates an environment.

**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.
- If you do not include the `workspace` query parameter, the system creates the environment in the oldest personal Internal workspace you own.


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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /environments:
    post:
      operationId: createEnvironment
      summary: Create an environment
      description: >
        Creates an environment.


        **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.

        - If you do not include the `workspace` query parameter, the system
        creates the environment in the oldest personal Internal workspace you
        own.
      tags:
        - environments
      parameters:
        - name: workspace
          in: query
          description: The workspace's ID.
          required: true
          schema:
            $ref: '#/components/schemas/workspaceId'
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/createEnvironmentResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateEnvironmentRequestBadRequestError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateEnvironmentRequestUnauthorizedError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateEnvironmentRequestForbiddenError'
        '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/CreateEnvironmentRequestInternalServerError
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createEnvironment'
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:
    workspaceId:
      type: string
      title: workspaceId
    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
    CreateEnvironmentEnvironment:
      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.
      required:
        - name
      description: Information about the environment.
      title: CreateEnvironmentEnvironment
    createEnvironment:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/CreateEnvironmentEnvironment'
          description: Information about the environment.
      title: createEnvironment
    CreateEnvironmentResponseEnvironment:
      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: CreateEnvironmentResponseEnvironment
    createEnvironmentResponse:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/CreateEnvironmentResponseEnvironment'
          description: Information about the environment.
      title: createEnvironmentResponse
    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
    CreateEnvironmentRequestBadRequestError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorNameMessageDetails'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateEnvironmentRequestBadRequestError
    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
    CreateEnvironmentRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateEnvironmentRequestUnauthorizedError
    CreateEnvironmentRequestForbiddenError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateEnvironmentRequestForbiddenError
    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
    CreateEnvironmentRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: CreateEnvironmentRequestInternalServerError
  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 Environment",
    "uid": "12345678-5daabc50-8451-43f6-922d-96b403b4f28e"
  }
}
```

**SDK Code**

```python Successful Response
import requests

url = "https://api.getpostman.com/environments"

querystring = {"workspace":"1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"}

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

response = requests.post(url, headers=headers, params=querystring)

print(response.json())
```

```javascript Successful Response
const url = 'https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
const options = {
  method: 'POST',
  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?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"

	req, _ := http.NewRequest("POST", 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?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")

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

request = Net::HTTP::Post.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.post("https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .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('POST', 'https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  '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?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9");
var request = new RestRequest(Method.POST);
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?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```

### Create Environment



**Request**

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

**Response**

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

**SDK Code**

```python Create Environment
import requests

url = "https://api.getpostman.com/environments"

querystring = {"workspace":"1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"}

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

response = requests.post(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript Create Environment
const url = 'https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"environment":{"name":"Test Environment","values":[{"enabled":true,"key":"collectionId","value":"12ece9e1-2abf-4edc-8e34-de66e74114d2","type":"default","description":"The collection\'s ID."},{"enabled":false,"key":"variable_1","value":"The variable_1 value.","type":"default","description":"Placeholder variable value."}]}}'
};

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

```go Create Environment
package main

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

func main() {

	url := "https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"

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

	req, _ := http.NewRequest("POST", 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 Create Environment
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")

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

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

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

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

HttpResponse<String> response = Unirest.post("https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"environment\": {\n    \"name\": \"Test Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      },\n      {\n        \"enabled\": false,\n        \"key\": \"variable_1\",\n        \"value\": \"The variable_1 value.\",\n        \"type\": \"default\",\n        \"description\": \"Placeholder variable value.\"\n      }\n    ]\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  'body' => '{
  "environment": {
    "name": "Test Environment",
    "values": [
      {
        "enabled": true,
        "key": "collectionId",
        "value": "12ece9e1-2abf-4edc-8e34-de66e74114d2",
        "type": "default",
        "description": "The collection\'s ID."
      },
      {
        "enabled": false,
        "key": "variable_1",
        "value": "The variable_1 value.",
        "type": "default",
        "description": "Placeholder variable value."
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create Environment
using RestSharp;

var client = new RestClient("https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"environment\": {\n    \"name\": \"Test Environment\",\n    \"values\": [\n      {\n        \"enabled\": true,\n        \"key\": \"collectionId\",\n        \"value\": \"12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n        \"type\": \"default\",\n        \"description\": \"The collection's ID.\"\n      },\n      {\n        \"enabled\": false,\n        \"key\": \"variable_1\",\n        \"value\": \"The variable_1 value.\",\n        \"type\": \"default\",\n        \"description\": \"Placeholder variable value.\"\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create Environment
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/environments?workspace=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```