> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Merge a fork

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

[Merges](https://learning.postman.com/docs/collaborating-in-postman/using-version-control/forking-elements/#merge-changes-from-a-fork) a forked environment back into its parent environment.


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

## Authentication

- `x-api-key` header (required)

## Servers

- `https://api.postman.com` (https://api.postman.com, default)
- `https://api.eu.postman.com` (https://api.eu.postman.com)

## Request

### Path parameters

- `environmentId` (string, required) — The environment's unique ID.

### Body (application/json)

- `source` (string, required) — The source environment's unique ID to merge data from.
- `deleteSource` (boolean, optional, default: false) — If true, the forked environment will be deleted.

## Response

### 200

Successful Response

- `environment` (object, optional) — Information about the merged environment.
  - `uid` (string, optional) — The merged environment's ID.

## Examples

### Successful Response

**Request**

```json
undefined
```

**Response**

```json
{
  "environment": {
    "uid": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957"
  }
}
```

**SDK Code**

```python Successful Response
import requests

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

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

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

print(response.json())
```

```javascript Successful Response
const url = 'https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges';
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.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges"

	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.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges")

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.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges")
  .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.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Successful Response
using RestSharp;

var client = new RestClient("https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges");
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.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges")! 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()
```

### Merge Environment Fork

**Request**

```json
{
  "source": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957",
  "deleteSource": false
}
```

**Response**

```json
{
  "environment": {
    "uid": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957"
  }
}
```

**SDK Code**

```python Merge Environment Fork
import requests

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

payload = {
    "source": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957",
    "deleteSource": False
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Merge Environment Fork
const url = 'https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"source":"12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957","deleteSource":false}'
};

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

```go Merge Environment Fork
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"source\": \"12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957\",\n  \"deleteSource\": false\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 Merge Environment Fork
require 'uri'
require 'net/http'

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

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  \"source\": \"12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957\",\n  \"deleteSource\": false\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"source\": \"12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957\",\n  \"deleteSource\": false\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges', [
  'body' => '{
  "source": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957",
  "deleteSource": false
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Merge Environment Fork
using RestSharp;

var client = new RestClient("https://api.postman.com/environments/12345678-5daabc50-8451-43f6-922d-96b403b4f28e/merges");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"source\": \"12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957\",\n  \"deleteSource\": false\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Merge Environment Fork
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "source": "12345678-d9c7dc8f-904e-4bba-99b5-4d490aae1957",
  "deleteSource": false
] as [String : Any]

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

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