POST
/
api
/
v1
/
context-variables
/
create

Create Context Variable Definition

Create a new context variable definition that can be used in contacts or your business profile.

Endpoint

POST /api/v1/context-variables/create

Authentication

This endpoint requires an API key with the can_write_contacts permission.

Request Body

ParameterTypeRequiredDescription
namestringYesVariable name (API identifier, e.g., last_payment_date)
display_namestringYesUser-friendly display name (e.g., “Last Payment Date”)
descriptionstringNoOptional description of the variable
variable_typestringYesData type (text, number, date, boolean, select)
context_typestringYesContext type (contact, business)
select_optionsarrayNoAvailable options for select type variables

Example Request Body

{
  "name": "membership_level",
  "display_name": "Membership Level",
  "description": "Customer's membership tier",
  "variable_type": "select",
  "context_type": "contact",
  "select_options": ["Bronze", "Silver", "Gold", "Platinum"]
}

Response

{
  "id": 3,
  "name": "membership_level",
  "display_name": "Membership Level",
  "message": "Variable definition created successfully"
}

Error Codes

Status CodeError CodeDescription
400missing_parameterA required parameter is missing
400duplicate_variableA variable with this name already exists
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
500server_errorAn unexpected server error occurred

Example Request

curl -X POST 'https://api.klen.ai/api/v1/context-variables/create' \
  -H 'Authorization: Bearer klen_abcdef123456789' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "membership_level",
    "display_name": "Membership Level",
    "description": "Customer'\''s membership tier",
    "variable_type": "select",
    "context_type": "contact",
    "select_options": ["Bronze", "Silver", "Gold", "Platinum"]
  }'

Example Response

{
  "id": 3,
  "name": "membership_level",
  "display_name": "Membership Level",
  "message": "Variable definition created successfully"
}

Valid Variable Types

TypeDescriptionSample Values
textText strings”Premium Support”, “East Region”
numberNumeric values42, 99.95, -10
dateDate values (stored in ISO format)“2023-12-01”, “2023-01-15T14:30:00Z”
booleanTrue/false valuestrue, false
selectValue from predefined options”Gold” (from provided options)

Notes

  • Variable names should be lowercase, contain only letters, numbers, and underscores
  • Variable names must be unique within their context type for your account
  • For select type variables, you must provide an array of options in the select_options field
  • The variable definition will be created for the account associated with the API key