Create a context field
POST <your-unleash-url>/api/admin/context
Authorization
name: Authorizationtype: apiKeyin: headerdescription: API key needed to access this API
Endpoint that allows creation of custom context fields
Request
- application/json
Body
required
createContextFieldSchema
- description string
A description of the context field
- stickiness boolean
true
if this field should be available for use with custom stickiness, otherwisefalse
- sortOrder integer
How this context field should be sorted if no other sort order is selected
legalValues object[]
- name string required
The name of the context field.
Responses
- 201
The resource was successfully created.
Response Headers
- application/json
- Schema
- Example (from schema)
Schema
- name string required
The name of the context field
- description string nullable
The description of the context field.
- stickiness boolean
Does this context field support being used for stickiness calculations
- sortOrder integer
Used when sorting a list of context fields. Is also used as a tiebreaker if a list of context fields is sorted alphabetically.
- createdAt date-time nullable
When this context field was created
- usedInFeatures integer nullable
Number of projects where this context field is used in
- usedInProjects integer nullable
Number of projects where this context field is used in
legalValues object[]
{
"name": "userId",
"description": "Used to uniquely identify users",
"stickiness": true,
"sortOrder": 900,
"createdAt": "2023-06-29T10:19:00.000Z",
"usedInFeatures": 3,
"usedInProjects": 2,
"legalValues": [
{
"value": "#c154c1",
"description": "Deep fuchsia"
}
]
}
Authorization
name: Authorizationtype: apiKeyin: headerdescription: API key needed to access this API
Request
Request
curl / cURL
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
python / requests
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
go / native
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
nodejs / native
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
ruby / Net::HTTP
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
csharp / httpclient
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
php / cURL
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
java / OkHttp
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
powershell / RestMethod
curl -L -X POST '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <API_KEY_VALUE>' \
--data-raw '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'