Create Property Class

Creates a new property class and returns its JSON representation.

Request

HTTP Request

POST /node/api/property-classes

Permissions

manage-property-classes

Request body

Request body contains new property class.

Модель класса свойств
Field Type Description

name

String

Name of the property class.

description

String

Description of the property class.

value_type_id

String

ID of the value type this property class uses.

value

Object

Default value of the property.

multiple

Boolean

Whether this property class has multiple values per key.

source

String

ID of the dictionary used as the source of the values for dictionary value type.

mask

String

Filter for the acceptable value that is defined with a regular expression.

system

Boolean

Whether this is a built-in property class.

id

String

ID of the property class.

multiple_separator

String

String that separates multiple values when displayed in the web interface.

value_display_template

String

Template used when displaying values in a web interface. You can use {{0}} to access the property’s value.

Dictionaries use the following indexing – you can access the key with {{0}}; {{1}}{{N}} used to access dictionary’s values.

{
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": ""
}

Response

Returns a JSON representation of a created property class.

Example

Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/property-classes

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": ""
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/property-classes";
let auth = "Basic " + btoa(login + ":" + password);

let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", auth);

let data = JSON.stringify({
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": ""
});

let requestOptions = {
    method: "POST",
    headers: headers,
    body: data
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log("error", error));
const http = require("http");

let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/property-classes";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");

let options = {
    "method": "POST",
    "hostname": saymonHostname,
    "headers": {
        "Authorization": auth,
        "Content-Type": "application/json"
    },
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

let data = JSON.stringify({
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": ""
});

req.write(data);
req.end();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/property-classes"

body = {
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": ""
}

response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)

Response

{
    "name": "Devices",
    "description": "Water monitoring devices",
    "value_type_id": "dictionary",
    "value": "",
    "multiple": true,
    "multiple_separator": ";",
    "value_display_template": "Device: {{1}} ({{2}})",
    "source": "66e41e89029ed40f1105e59e",
    "mask": "",
    "id": "66e9850cbb17541c30c88348"
}