Skip to main content

Create a context field

POST 

<your-unleash-url>/api/admin/context

Endpoint that allows creation of custom context fields

Request

Bodyrequired

createContextFieldSchema

    descriptionstring

    A description of the context field

    Example: The user's subscription tier
    stickinessboolean

    true if this field should be available for use with custom stickiness, otherwise false

    Example: false
    sortOrderinteger

    How this context field should be sorted if no other sort order is selected

    Example: 2
    legalValues object[]

    A list of allowed values for this context field

  • Array [
  • valuestringrequired

    The valid value

    Example: #c154c1
    descriptionstring

    Describes this specific legal value

    Example: Deep fuchsia
  • ]
  • namestringrequired

    The name of the context field.

    Example: subscriptionTier

Responses

The resource was successfully created.

Response Headers
    location

    The location of the newly created resource.

Schema
    namestringrequired

    The name of the context field

    Example: userId
    descriptionstringnullable

    The description of the context field.

    Example: Used to uniquely identify users
    stickinessboolean

    Does this context field support being used for stickiness calculations

    Example: true
    sortOrderinteger

    Used when sorting a list of context fields. Is also used as a tiebreaker if a list of context fields is sorted alphabetically.

    Example: 900
    createdAtdate-timenullable

    When this context field was created

    Example: 2023-06-29T10:19:00.000Z
    usedInFeaturesintegernullable

    Number of projects where this context field is used in

    Example: 3
    usedInProjectsintegernullable

    Number of projects where this context field is used in

    Example: 2
    legalValues object[]

    Allowed values for this context field schema. Can be used to narrow down accepted input

  • Array [
  • valuestringrequired

    The valid value

    Example: #c154c1
    descriptionstring

    Describes this specific legal value

    Example: Deep fuchsia
  • ]

Authorization: Authorization

name: Authorizationtype: apiKeyin: headerdescription: API key needed to access this API
curl -L '<your-unleash-url>/api/admin/context' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: <Authorization>' \
-d '{
"description": "The user'\''s subscription tier",
"stickiness": false,
"sortOrder": 2,
"legalValues": [
{
"value": "gold"
},
{
"value": "silver"
},
{
"value": "crystal"
}
],
"name": "subscriptionTier"
}'
Request Collapse all
Base URL
<your-unleash-url>
Auth
Body required
{
  "description": "The user's subscription tier",
  "stickiness": false,
  "sortOrder": 2,
  "legalValues": [
    {
      "value": "gold"
    },
    {
      "value": "silver"
    },
    {
      "value": "crystal"
    }
  ],
  "name": "subscriptionTier"
}
ResponseClear

Click the Send API Request button above and see the response here!