Create an Environment
1 min
POST
https://api.optimizely.com/v2/environments
Body Parameters
- bodyEnvironmentrequiredDescription
- archivedbooleanDescription
- datafileDatafile
- idintegerDescription
- latest_file_sizeintegerDescription
- other_urlsstring[]Description
- revisionintegerDescription
- sdk_keystringDescription
- urlstring<url>DescriptionFormaturl
- descriptionstringExampleDescription
- has_restricted_permissionsbooleanDescriptionDefaultfalse
- keystringrequiredDescriptionMax Length64Pattern^[a-zA-Z0-9_\-]+$
- namestringrequiredExampleDescription
- priorityintegerExampleDescription
- project_idintegerrequiredDescription
Responses
201
- Environment
- archivedbooleanDescription
- createdstringDescription
- datafileDatafile
- idintegerDescription
- latest_file_sizeintegerDescription
- other_urlsstring[]Description
- revisionintegerDescription
- sdk_keystringDescription
- urlstring<url>DescriptionFormaturl
- descriptionstringExampleDescription
- has_restricted_permissionsbooleanDescriptionDefaultfalse
- idintegerDescription
- is_primarybooleanDescription
- keystringrequiredDescriptionMax Length64Pattern^[a-zA-Z0-9_\-]+$
- last_modifiedstringDescription
- namestringrequiredExampleDescription
- priorityintegerExampleDescription
- project_idintegerrequiredDescription
400
- Error
- codestring
- messagestring
- messagesobject
- uuidstring<uuid>Formatuuid
401
- Error
- codestring
- messagestring
- messagesobject
- uuidstring<uuid>Formatuuid
403
- Error
- codestring
- messagestring
- messagesobject
- uuidstring<uuid>Formatuuid
default
- Error
- codestring
- messagestring
- messagesobject
- uuidstring<uuid>Formatuuid
curl
curl --request POST \
--url https://api.optimizely.com/v2/environments \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"key": "",
"name": "Staging",
"project_id": ""
}'javascript
var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("content-type", "application/json");
var raw = JSON.stringify({
"key": "",
"name": "Staging",
"project_id": ""
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.optimizely.com/v2/environments", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.optimizely.com/v2/environments")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["accept"] = "application/json"
request["content-type"] = "application/json"
request.body = JSON.dump({
"key": "",
"name": "Staging",
"project_id": ""
})
response = https.request(request)
puts response.read_body
python
import requests
import json
url = "https://api.optimizely.com/v2/environments"
payload = json.dumps({
"key": "",
"name": "Staging",
"project_id": ""
})
headers = {
'accept': 'application/json',
'content-type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
201
// Return the created Environment
{
"archived": false,
"created": "",
"datafile": {
"id": 0,
"latest_file_size": 0,
"other_urls": [
""
],
"revision": 0,
"sdk_key": "",
"url": ""
},
"description": "For testing purposes before deploying to Production",
"has_restricted_permissions": false,
"id": 0,
"is_primary": false,
"key": "",
"last_modified": "",
"name": "Staging",
"priority": 3,
"project_id": 0
}400
// Invalid request body supplied
{
"code": "",
"message": "",
"messages": {},
"uuid": ""
}401
// Invalid credentials
{
"code": "",
"message": "",
"messages": {},
"uuid": ""
}403
// You do not have permission to create an Environment in the specified Project
{
"code": "",
"message": "",
"messages": {},
"uuid": ""
}default
// Unexpected error
{
"code": "",
"message": "",
"messages": {},
"uuid": ""
}