> 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 a fork

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

Creates a [fork](https://learning.postman.com/docs/collaborating-in-postman/using-version-control/forking-elements/) of an existing environment.

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /environments/{environmentId}/forks:
    post:
      operationId: forkEnvironment
      summary: Create a fork
      description: >-
        Creates a
        [fork](https://learning.postman.com/docs/collaborating-in-postman/using-version-control/forking-elements/)
        of an existing environment.
      tags:
        - environments
      parameters:
        - name: environmentId
          in: path
          description: The environment's unique ID.
          required: true
          schema:
            $ref: '#/components/schemas/environmentUid'
        - name: workspaceId
          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/forkEnvironmentResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForkEnvironmentRequestUnauthorizedError'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForkEnvironmentRequestInternalServerError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/forkEnvironment'
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:
    environmentUid:
      type: string
      format: uid
      title: environmentUid
    workspaceId:
      type: string
      title: workspaceId
    forkEnvironment:
      type: object
      properties:
        forkName:
          type: string
          description: The forked environment's label.
      required:
        - forkName
      title: forkEnvironment
    ForkEnvironmentResponseEnvironment:
      type: object
      properties:
        uid:
          type: string
          format: uid
          description: The forked environment's ID.
        name:
          type: string
          description: The name of the forked environment.
        forkName:
          type: string
          description: The forked environment's label.
      description: Information about the forked environment.
      title: ForkEnvironmentResponseEnvironment
    forkEnvironmentResponse:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/ForkEnvironmentResponseEnvironment'
          description: Information about the forked environment.
      title: forkEnvironmentResponse
    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
    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
    ForkEnvironmentRequestUnauthorizedError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: ForkEnvironmentRequestUnauthorizedError
    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
    ForkEnvironmentRequestInternalServerError:
      oneOf:
        - $ref: '#/components/schemas/commonErrorTypeTitleDetail'
        - $ref: '#/components/schemas/commonErrorTypeTitleDetailStatus'
        - $ref: '#/components/schemas/commonErrorNameMessage'
      title: ForkEnvironmentRequestInternalServerError
  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": {
    "uid": "12345678-0fcea3ba-abcf-49c3-9f48-669c208fef25",
    "name": "Testing Environment",
    "forkName": "Test Fork"
  }
}
```

**SDK Code**

```python Successful Response
import requests

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

querystring = {"workspaceId":"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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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()
```

### Fork Environment



**Request**

```json
{
  "forkName": "My fork"
}
```

**Response**

```json
{
  "environment": {
    "uid": "12345678-0fcea3ba-abcf-49c3-9f48-669c208fef25",
    "name": "Testing Environment",
    "forkName": "Test Fork"
  }
}
```

**SDK Code**

```python Fork Environment
import requests

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

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

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

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

print(response.json())
```

```javascript Fork Environment
const url = 'https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"forkName":"My fork"}'
};

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

```go Fork Environment
package main

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

func main() {

	url := "https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9"

	payload := strings.NewReader("{\n  \"forkName\": \"My fork\"\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 Fork Environment
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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  \"forkName\": \"My fork\"\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"forkName\": \"My fork\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=1f0df51a-8658-4ee8-a2a1-d2567dfa09a9', [
  'body' => '{
  "forkName": "My fork"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Fork Environment
using RestSharp;

var client = new RestClient("https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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  \"forkName\": \"My fork\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Fork Environment
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/forks?workspaceId=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()
```