# Clones an environment POST https://app.unleash-instance.example.com/api/admin/environments/{name}/clone Content-Type: application/json **Enterprise feature** Given an existing environment name and a set of options, this will create a copy of that environment Reference: https://docs.getunleash.io/api/clone-environment ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Clones an environment version: endpoint_environments.cloneEnvironment paths: /api/admin/environments/{name}/clone: post: operationId: clone-environment summary: Clones an environment description: >- **Enterprise feature** Given an existing environment name and a set of options, this will create a copy of that environment tags: - - subpackage_environments parameters: - name: name in: path required: true schema: type: string - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '200': description: environmentSchema content: application/json: schema: $ref: '#/components/schemas/environmentSchema' '400': description: The request data does not match what we expect. content: {} '401': description: >- Authorization information is missing or invalid. Provide a valid API token as the `authorization` header, e.g. `authorization:*.*.my-admin-token`. content: {} requestBody: description: cloneEnvironmentSchema content: application/json: schema: $ref: '#/components/schemas/cloneEnvironmentSchema' components: schemas: cloneEnvironmentSchema: type: object properties: name: type: string description: The name of the new cloned environment, this cannot be changed later type: type: string description: Updates the type of environment (i.e. development or production). projects: type: array items: type: string description: >- A list of projects that should be included in the cloned environment. clonePermissions: type: boolean description: >- Copies the RBAC permissions from the source environment if true. Defaults to true required: - name - type environmentSchema: type: object properties: name: type: string description: The name of the environment type: type: string description: >- The [type of environment](https://docs.getunleash.io/concepts/environments#environment-types). enabled: type: boolean description: >- `true` if the environment is enabled for the project, otherwise `false`. protected: type: boolean description: >- `true` if the environment is protected, otherwise `false`. A *protected* environment can not be deleted. sortOrder: type: integer description: >- Priority of the environment in a list of environments, the lower the value, the higher up in the list the environment will appear. Needs to be an integer projectCount: type: - integer - 'null' description: The number of projects with this environment apiTokenCount: type: - integer - 'null' description: The number of API tokens for the project environment enabledToggleCount: type: - integer - 'null' description: The number of enabled toggles for the project environment requiredApprovals: type: - integer - 'null' description: >- Experimental field. The number of approvals required before a change request can be applied in this environment. required: - name - type - enabled - protected - sortOrder ``` ## SDK Code Examples ```python import requests url = "https://app.unleash-instance.example.com/api/admin/environments/name/clone" payload = { "name": "development", "type": "development" } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.unleash-instance.example.com/api/admin/environments/name/clone'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"name":"development","type":"development"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://app.unleash-instance.example.com/api/admin/environments/name/clone" payload := strings.NewReader("{\n \"name\": \"development\",\n \"type\": \"development\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") 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 require 'uri' require 'net/http' url = URI("https://app.unleash-instance.example.com/api/admin/environments/name/clone") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"development\",\n \"type\": \"development\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.unleash-instance.example.com/api/admin/environments/name/clone") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"name\": \"development\",\n \"type\": \"development\"\n}") .asString(); ``` ```php request('POST', 'https://app.unleash-instance.example.com/api/admin/environments/name/clone', [ 'body' => '{ "name": "development", "type": "development" }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.unleash-instance.example.com/api/admin/environments/name/clone"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"development\",\n \"type\": \"development\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "name": "development", "type": "development" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://app.unleash-instance.example.com/api/admin/environments/name/clone")! 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() ```