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"
}
'
import requests

url = "https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom"

payload = {
"name": "user.preferred_language",
"sourceType": "user_metadata",
"description": "The preferred language of the user",
"sourcePath": "language",
"constantValue": "en",
"defaultValue": "en"
}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'user.preferred_language',
sourceType: 'user_metadata',
description: 'The preferred language of the user',
sourcePath: 'language',
constantValue: 'en',
defaultValue: 'en'
})
};

fetch('https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'user.preferred_language',
'sourceType' => 'user_metadata',
'description' => 'The preferred language of the user',
'sourcePath' => 'language',
'constantValue' => 'en',
'defaultValue' => 'en'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom"

payload := strings.NewReader("{\n \"name\": \"user.preferred_language\",\n \"sourceType\": \"user_metadata\",\n \"description\": \"The preferred language of the user\",\n \"sourcePath\": \"language\",\n \"constantValue\": \"en\",\n \"defaultValue\": \"en\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"user.preferred_language\",\n \"sourceType\": \"user_metadata\",\n \"description\": \"The preferred language of the user\",\n \"sourcePath\": \"language\",\n \"constantValue\": \"en\",\n \"defaultValue\": \"en\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://{appId}.api-{region}.cometchat.io/v3/ai-agents/agent-builder/agents/variables/custom")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"user.preferred_language\",\n \"sourceType\": \"user_metadata\",\n \"description\": \"The preferred language of the user\",\n \"sourcePath\": \"language\",\n \"constantValue\": \"en\",\n \"defaultValue\": \"en\"\n}"

response = http.request(request)
puts response.read_body
{
  "_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
}
For the complete error reference, see Error Guide.

Authorizations

apikey
string
header
required

API Key (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

200 - application/json

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
string
Example:

"user_metadata"

sourcePath
string
Example:

"metadata.plan"

constantValue
string
Example:

"premium"

defaultValue
string
Example:

"free"

category
string
Example:

"custom"

createdAt
number
Example:

1700000000000

updatedAt
number
Example:

1700000000000