Skip to main content
POST
/
ai-agents
/
agent-builder
/
agents
/
variables
/
custom
Create Custom Variable
curl --request POST \
  --url https://{appid}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom \
  --header 'Content-Type: application/json' \
  --header 'apikey: <api-key>' \
  --data '
{
  "name": "user.preferred_language",
  "sourceType": "user_metadata",
  "description": "The preferred language of the user",
  "sourcePath": "language",
  "constantValue": "en",
  "defaultValue": "en"
}
'
{
  "_id": "507f1f77bcf86cd799439011",
  "appId": "my-app-id",
  "name": "user.plan",
  "description": "The user subscription plan",
  "sourceType": "user_metadata",
  "sourcePath": "metadata.plan",
  "constantValue": "",
  "defaultValue": "free",
  "category": "custom",
  "createdAt": 1700000000000,
  "updatedAt": 1700000000000
}

Authorizations

apikey
string
header
required

API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).

Body

application/json
name
string
required

Unique variable name. Must start with a letter and contain only alphanumeric characters, underscores, and dots.

Maximum string length: 50
Pattern: ^[a-zA-Z][a-zA-Z0-9_.]*$
Example:

"user.preferred_language"

sourceType
enum<string>
required

Source from which the variable value is resolved

Available options:
message_metadata,
user_metadata,
constant
Example:

"user_metadata"

description
string

Human-readable description of the variable

Maximum string length: 200
Example:

"The preferred language of the user"

sourcePath
string

Dot-notation path to extract the value from the source metadata

Maximum string length: 100
Example:

"language"

constantValue
string

Fixed value used when sourceType is constant

Maximum string length: 500
Example:

"en"

defaultValue
string

Fallback value used when the source path does not resolve

Maximum string length: 200
Example:

"en"

Response

Custom variable created successfully

_id
string
Example:

"507f1f77bcf86cd799439011"

appId
string
Example:

"my-app-id"

name
string
Example:

"user.plan"

description
string
Example:

"The user subscription plan"

sourceType
enum<string>
Available options:
message_metadata,
user_metadata,
constant
Example:

"user_metadata"

sourcePath
string
Example:

"metadata.plan"

constantValue
string
Example:

""

defaultValue
string
Example:

"free"

category
enum<string>
Available options:
custom
Example:

"custom"

createdAt
number
Example:

1700000000000

updatedAt
number
Example:

1700000000000