Create Variable

Create Variable

POST https://api.ocamba.com/v1/hood/variables
Creates a new Variable object

Note

The navigation group_type includes the types url and referrer.

The page_elements group_type includes the types dom-element and element-visibility.

The page_variables group_type includes the types 1st-party-cookie, data-layer-variable, and custom-js.

The utilities group_type includes the type custom-event.

Rate limits:

  • Burst: 10/s
  • Steady: 150/m

Request schema

body

Response schemas

curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "url variable",
  "group_type": "navigation",
  "type": "url",
  "settings": {
    "component_type": "host-name",
    "strip": true
  },
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "url variable",
      "group_type": "navigation",
      "type": "url",
      "settings": {
        "component_type": "host-name",
        "strip": true
      },
      "formatting": {
        "change_case": "lowercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "url variable",
    "group_type" => "navigation",
    "type" => "url",
    "settings" => [
      "component_type" => "host-name",
      "strip" => true
    ],
    "formatting" => [
      "change_case" => "lowercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '"{\n  \"name\": \"referrer variable\",\n  \"group_type\": \"navigation\",\n  \"type\": \"referrer\",\n  \"settings\": {\n      \"component_type\": \"path\",\n      \"default_pages\": \"/home\",\n  },\n  \"formatting\": {\n      \"change_case\": \"lowercase\",\n      \"convert_null_to\": \"test\",\n      \"convert_undefined_to\": \"test\",\n      \"convert_true_to\": \"false\"\n  }\n}"'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    "{\n  \"name\": \"referrer variable\",\n  \"group_type\": \"navigation\",\n  \"type\": \"referrer\",\n  \"settings\": {\n      \"component_type\": \"path\",\n      \"default_pages\": \"/home\",\n  },\n  \"formatting\": {\n      \"change_case\": \"lowercase\",\n      \"convert_null_to\": \"test\",\n      \"convert_undefined_to\": \"test\",\n      \"convert_true_to\": \"false\"\n  }\n}"
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  "[\n  \"name\" => \"referrer variable\",\n  \"group_type\" => \"navigation\",\n  \"type\" => \"referrer\",\n  \"settings\" => [\n      \"component_type\" => \"path\",\n      \"default_pages\" => \"/home\",\n  ],\n  \"formatting\" => [\n      \"change_case\" => \"lowercase\",\n      \"convert_null_to\" => \"test\",\n      \"convert_undefined_to\" => \"test\",\n      \"convert_true_to\" => \"false\"\n  ]\n]"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "page visibility variable",
  "group_type": "page-elements",
  "type": "element-visibility",
  "settings": {
    "selection_method": "id",
    "output_type": "true/false",
    "percent": 50
  },
  "formatting": {
    "change_case": "uppercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "page visibility variable",
      "group_type": "page-elements",
      "type": "element-visibility",
      "settings": {
        "selection_method": "id",
        "output_type": "true/false",
        "percent": 50
      },
      "formatting": {
        "change_case": "uppercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "page visibility variable",
    "group_type" => "page-elements",
    "type" => "element-visibility",
    "settings" => [
      "selection_method" => "id",
      "output_type" => "true/false",
      "percent" => 50
    ],
    "formatting" => [
      "change_case" => "uppercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "dom element variable",
  "group_type": "page-elements",
  "type": "dom-element",
  "settings": {
    "selection_method": "id",
    "element_id": "TEST123",
    "attribute_name": "example-name"
  },
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "dom element variable",
      "group_type": "page-elements",
      "type": "dom-element",
      "settings": {
        "selection_method": "id",
        "element_id": "TEST123",
        "attribute_name": "example-name"
      },
      "formatting": {
        "change_case": "lowercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "dom element variable",
    "group_type" => "page-elements",
    "type" => "dom-element",
    "settings" => [
      "selection_method" => "id",
      "element_id" => "TEST123",
      "attribute_name" => "example-name"
    ],
    "formatting" => [
      "change_case" => "lowercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '"{\n  \"name\": \"1st-party-cookie variable\",\n  \"group_type\": \"page-variables\",\n  \"type\": \"1st-party-cookie\",\n  \"settings\": {\n      \"cookie_name\": \"example-name\"\n      \"uri-decode\": false\n  },\n  \"formatting\": {\n      \"change_case\": \"lowercase\",\n      \"convert_null_to\": \"test\",\n      \"convert_undefined_to\": \"test\",\n      \"convert_true_to\": \"false\"\n  }   \n}           "'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    "{\n  \"name\": \"1st-party-cookie variable\",\n  \"group_type\": \"page-variables\",\n  \"type\": \"1st-party-cookie\",\n  \"settings\": {\n      \"cookie_name\": \"example-name\"\n      \"uri-decode\": false\n  },\n  \"formatting\": {\n      \"change_case\": \"lowercase\",\n      \"convert_null_to\": \"test\",\n      \"convert_undefined_to\": \"test\",\n      \"convert_true_to\": \"false\"\n  }   \n}           "
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  "[\n  \"name\" => \"1st-party-cookie variable\",\n  \"group_type\" => \"page-variables\",\n  \"type\" => \"1st-party-cookie\",\n  \"settings\" => [\n      \"cookie_name\" => \"example-name\"\n      \"uri-decode\" => false\n  ],\n  \"formatting\" => [\n      \"change_case\" => \"lowercase\",\n      \"convert_null_to\" => \"test\",\n      \"convert_undefined_to\" => \"test\",\n      \"convert_true_to\" => \"false\"\n  ]   \n]           "
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "data layer variable",
  "group_type": "page-variables",
  "type": "data-layer-variable",
  "settings": {
    "variable_name": "example-name",
    "default_value": "test"
  },
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "data layer variable",
      "group_type": "page-variables",
      "type": "data-layer-variable",
      "settings": {
        "variable_name": "example-name",
        "default_value": "test"
      },
      "formatting": {
        "change_case": "lowercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "data layer variable",
    "group_type" => "page-variables",
    "type" => "data-layer-variable",
    "settings" => [
      "variable_name" => "example-name",
      "default_value" => "test"
    ],
    "formatting" => [
      "change_case" => "lowercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "custom javascript variable",
  "group_type": "page-variables",
  "type": "custom-js",
  "settings": {
    "custom_js": "<script> </script>"
  },
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "custom javascript variable",
      "group_type": "page-variables",
      "type": "custom-js",
      "settings": {
        "custom_js": "<script> </script>"
      },
      "formatting": {
        "change_case": "lowercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "custom javascript variable",
    "group_type" => "page-variables",
    "type" => "custom-js",
    "settings" => [
      "custom_js" => "<script> </script>"
    ],
    "formatting" => [
      "change_case" => "lowercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl -X POST \
 "https://api.ocamba.com/v1/hood/variables" \
  -H "Authorization: Bearer {TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "custom event variable",
  "group_type": "utilities",
  "type": "custom-event",
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  }
}'
const url = 'https://api.ocamba.com/v1/hood/variables';
const options = {
  method: 'POST',
  headers: {
    Authorization: "Bearer {TOKEN}",
    'Content-Type': "application/json"
  },
  body: JSON.stringify(
    {
      "name": "custom event variable",
      "group_type": "utilities",
      "type": "custom-event",
      "formatting": {
        "change_case": "lowercase",
        "convert_null_to": "test",
        "convert_undefined_to": "test",
        "convert_true_to": "false"
      }
    }
  )
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
$ch = curl_init("https://api.ocamba.com/v1/hood/variables");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Bearer {TOKEN}",
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
  [
    "name" => "custom event variable",
    "group_type" => "utilities",
    "type" => "custom-event",
    "formatting" => [
      "change_case" => "lowercase",
      "convert_null_to" => "test",
      "convert_undefined_to" => "test",
      "convert_true_to" => "false"
    ]
  ]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

Responses

201 Created

{
  "id": "1000",
  "company_id": "4391241",
  "name": "url variable",
  "group_type": "navigation",
  "type": "url",
  "settings": {
    "component_type": "host-name",
    "strip": true
  },
  "formatting": {
    "change_case": "lowercase",
    "convert_null_to": "test",
    "convert_undefined_to": "test",
    "convert_true_to": "false"
  },
  "system": 0,
  "is_visible": false,
  "create_time": "2025-01-22 13:26:27",
  "update_time": "2025-01-22 13:26:27"
}

400 Bad Request

{
  "code": 400,
  "title": "Bad request.",
  "message": "The request is not valid.",
  "trace_id": "99a84211-f73d-4ff8-acdf-eb3e06bb9d62"
}

500 Internal Server Error

{
  "code": 500,
  "title": "Internal server error.",
  "trace_id": "99a84211-f73d-4ff8-acdf-eb3e06bb9d62"
}
Responses