PUT
/
api
/
v1
/
context-variables
/
{variable_id}
/
update

Update Context Variable Definition

Update an existing context variable definition. You can update the display name, description, variable type, and select options.

Endpoint

PUT /api/v1/context-variables/{variable_id}/update

You can also use PATCH for partial updates:

PATCH /api/v1/context-variables/{variable_id}/update

Authentication

This endpoint requires an API key with the can_write_contacts permission.

Path Parameters

ParameterTypeRequiredDescription
variable_idintegerYesID of the variable definition to update

Request Body

ParameterTypeRequiredDescription
display_namestringNoUser-friendly display name (e.g., “Last Payment Date”)
descriptionstringNoOptional description of the variable
variable_typestringNoData type (text, number, date, boolean, select)
select_optionsarrayNoAvailable options for select type variables

Note: The name and context_type fields cannot be changed after creation.

Example Request Body

{
  "display_name": "Updated Display Name",
  "description": "Updated description",
  "select_options": ["Option 1", "Option 2", "Option 3"]
}

Response

{
  "id": 3,
  "name": "membership_level",
  "display_name": "Updated Display Name",
  "message": "Variable definition updated successfully"
}

Error Codes

Status CodeError CodeDescription
400invalid_jsonInvalid JSON payload
401authentication_requiredNo API key was provided
401invalid_keyThe API key is invalid or inactive
403permission_deniedThe API key doesn’t have the required permission
404not_foundVariable definition not found
500server_errorAn unexpected server error occurred

Example Request

curl -X PUT 'https://api.klen.ai/api/v1/context-variables/3/update' \
  -H 'Authorization: Bearer klen_abcdef123456789' \
  -H 'Content-Type: application/json' \
  -d '{
    "display_name": "Updated Display Name",
    "description": "Updated description",
    "select_options": ["Option 1", "Option 2", "Option 3"]
  }'

Example Response

{
  "id": 3,
  "name": "membership_level",
  "display_name": "Updated Display Name",
  "message": "Variable definition updated successfully"
}

Notes

  • You cannot update the name or context_type of an existing variable definition
  • If you need to change these, delete the existing definition and create a new one
  • When updating a select type variable, provide the complete array of options (not just new ones)
  • You can only update variable definitions that belong to your account
  • Default system variables (is_default: true) cannot be modified