Create a new Custom Field
1 min
POST
https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields
Path Parameters
- project_idintegerrequiredExampleDescription
Body Parameters
- bodyCustomFieldRequestBodyrequired
- archivedbooleanDescription
- default_valuestringExampleDescription
- descriptionstringExampleDescriptionMax Length1000
- entity_typestring<flag | rule>requiredExampleDescriptionAllowedflagrule
- field_typestring<text | number | boolean | link | label>requiredExampleDescriptionAllowedtextnumberbooleanlinklabel
- keystringrequiredExampleDescription
- namestringrequiredExampleDescription
- requiredbooleanDescription
- validationobjectExample
{ "max": 100, "max_length": 255, "min": 1 }Description- allow_multi_selectbooleanDescription
- decimal_placesintegerExampleDescription
- field_optionsstring[]Example
[ "US", "EU", "APAC" ]
Description - maxnumberExampleDescription
- max_lengthintegerExampleDescription
- minnumberExampleDescription
- regexstringExampleDescription
- use_thousand_separatorbooleanExampleDescription
Responses
201
- CustomFieldDescription
- archivedbooleanDescription
- created_by_user_idstringExampleDescription
- created_timestring<date-time>ExampleDescriptionFormatdate-time
- default_valuestringExampleDescription
- descriptionstringExampleDescriptionMax Length1000
- entity_typestring<flag | rule>requiredExampleDescriptionAllowedflagrule
- field_typestring<text | number | boolean | link | label>requiredExampleDescriptionAllowedtextnumberbooleanlinklabel
- idintegerrequiredExampleDescription
- keystringrequiredExampleDescriptionMax Length64Pattern^[a-zA-Z0-9_\-]+$
- namestringrequiredExampleDescriptionMax Length255
- project_idinteger<int64>ExampleDescriptionFormatint64
- requiredbooleanrequiredDescription
- updated_timestring<date-time>ExampleDescriptionFormatdate-time
- validationobjectExample
{ "max": 100, "max_length": 255, "min": 1 }Description- allow_multi_selectbooleanDescription
- decimal_placesintegerExampleDescription
- field_optionsstring[]Example
[ "US", "EU", "APAC" ]
Description - maxnumberExampleDescription
- max_lengthintegerExampleDescription
- minnumberExampleDescription
- regexstringExampleDescription
- use_thousand_separatorbooleanExampleDescription
400
401
403
curl
curl --request POST \
--url https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"entity_type": "flag",
"field_type": "text",
"key": "analytics_team",
"name": "Analytics Team"
}'javascript
var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("content-type", "application/json");
var raw = JSON.stringify({
"entity_type": "flag",
"field_type": "text",
"key": "analytics_team",
"name": "Analytics Team"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields", 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/flags/v1//projects/{project_id}/custom_fields")
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({
"entity_type": "flag",
"field_type": "text",
"key": "analytics_team",
"name": "Analytics Team"
})
response = https.request(request)
puts response.read_body
python
import requests
import json
url = "https://api.optimizely.com/flags/v1//projects/{project_id}/custom_fields"
payload = json.dumps({
"entity_type": "flag",
"field_type": "text",
"key": "analytics_team",
"name": "Analytics Team"
})
headers = {
'accept': 'application/json',
'content-type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
201
// Successful retrieval of a Custom Field.
The response includes RESTful JSON (https://restfuljson.org/) styled links. If a
link is not present in the response, it indicates a user is not authorized to access
the related resource.
{
"archived": false,
"created_by_user_id": "[email protected]",
"created_time": "2024-01-01T10:00:00.000Z",
"default_value": "option1",
"description": "Custom field to tag experiments owned by the analytics team",
"entity_type": "flag",
"field_type": "text",
"id": 12345,
"key": "analytics_team",
"name": "Analytics Team",
"project_id": 98765,
"required": false,
"updated_time": "2024-01-01T10:00:00.000Z",
"validation": {
"allow_multi_select": false,
"decimal_places": 2,
"field_options": [
""
],
"max": 100,
"max_length": 255,
"min": 1,
"regex": "^[A-Za-z0-9_-]+$",
"use_thousand_separator": true
}
}400
// Malformed requests and invalid parameter names and types
401
// Invalid credentials
403
// Do not have permission to perform the operation