POST
/attributes/Create attribute
You can create custom attributes for any model.
Possible attribute types: boolean, date, datetime, fixed, float, integer, json, string.
| Attributes | Type | Required | Description |
|---|---|---|---|
| content_type | string | yes | The type of content you want create attribute for. Possible content types are: activity, clientuser, company, deal, product, ticket. |
| name | string | yes | A name of an attribute you want to create. Has to be at least 1 character, and cannot be longer than 32 characters. |
| value_type | string | yes | A type of the attribute value. Possible values: boolean, date, datetime, fixed, float, integer, json, string. |
| choices | array | no* | Array of option values for fixed choice attributes. Required when value_type is fixed. |
| allow_multiple_choices | boolean | no* | Allows multiple selections for fixed choice attributes. Required when value_type is fixed. |
* Required when value_type is fixed
Request
- CURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/attributes/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"value_type": "string",
"name": "API string attribute",
"content_type": "clientuser"
}'
var data = JSON.stringify({
"value_type": "string",
"name": "API string attribute",
"content_type": "clientuser"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/attributes/");
xhr.setRequestHeader("Authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("Accept", "*/*; version=2");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/attributes/",
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(array(
"value_type" => "string",
"name" => "API string attribute",
"content_type" => "clientuser"
)),
CURLOPT_HTTPHEADER => array(
"Accept: */*; version=2",
"Authorization: Token <your_64_char_api_key>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
import json
url = "https://<your_app_subdomain>.user.com/api/public/attributes/"
payload = json.dumps({
"value_type": "string",
"name": "API string attribute",
"content_type": "clientuser"
})
headers = {
'Authorization': 'Token <your_64_char_api_key>',
'Accept': '*/*; version=2',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Response
{
"id": 46,
"name": "API string attribute",
"name_std": "api_string_attribute",
"value_type": "string",
"content_type": "clientuser"
}
Fixed Choice Attributes Example
Request
- CURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/attributes/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"content_type": "clientuser",
"name": "Newsletter preferences",
"value_type": "fixed",
"choices": ["Daily digest", "Weekly summary", "Monthly newsletter", "Product updates"],
"allow_multiple_choices": true
}'
var data = JSON.stringify({
"content_type": "clientuser",
"name": "Newsletter preferences",
"value_type": "fixed",
"choices": ["Daily digest", "Weekly summary", "Monthly newsletter", "Product updates"],
"allow_multiple_choices": true
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/attributes/");
xhr.setRequestHeader("Authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("Accept", "*/*; version=2");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/attributes/",
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(array(
"content_type" => "clientuser",
"name" => "Newsletter preferences",
"value_type" => "fixed",
"choices" => array("Daily digest", "Weekly summary", "Monthly newsletter", "Product updates"),
"allow_multiple_choices" => true
)),
CURLOPT_HTTPHEADER => array(
"Accept: */*; version=2",
"Authorization: Token <your_64_char_api_key>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
import json
url = "https://<your_app_subdomain>.user.com/api/public/attributes/"
payload = json.dumps({
"content_type": "clientuser",
"name": "Newsletter preferences",
"value_type": "fixed",
"choices": ["Daily digest", "Weekly summary", "Monthly newsletter", "Product updates"],
"allow_multiple_choices": True
})
headers = {
'Authorization': 'Token <your_64_char_api_key>',
'Accept': '*/*; version=2',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Response
{
"id": 47,
"name": "Newsletter preferences",
"name_std": "newsletter_preferences",
"value_type": "fixed",
"content_type": "clientuser",
"choices": ["Daily digest", "Weekly summary", "Monthly newsletter", "Product updates"],
"allow_multiple_choices": true
}