Create Object

Creates a new object with data passed in a request body. Returns the created object in the JSON format.

Request

HTTP Request

POST /node/api/objects

Permissions

create-objects | manage-objects

Path parameters

No parameters required.

Body parameters

See the Object model.

Request body

To create a new object, you need to specify its name. See the Object model page for all available parameters.

{
    "name": "New Object",
    "parent_id": "1"
}

If the parent_id isn’t specified in the request body, it defaults to 1 (the root object).

Response

The response contains the created object in the JSON format. See the Object model page for more information.

Examples

Create a minimal object

This example shows how to create a new object with the name New Object and set its parent to the root object (id 1):

Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/objects

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "name": "New Object",
    "parent_id": "1"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/objects";
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": "New Object",
    "parent_id": "1"
});

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/objects";
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: "New Object",
    parent_id: "1"
});

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

login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/objects"
body = {
"name": "New Object",
"parent_id": "1"
}

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

Response

{
    "name": "New Object",
    "owner_id": "5e21b752308c3c66d64e072c",
    "object_groups": [],
    "geoposition": [],
    "child_ref_ids": [],
    "child_link_ids": [],
    "child_ids": [],
    "parent_id": "1",
    "weight": 1,
    "tags": [],
    "last_state_update": 1585035085802,
    "updated": 1585035085800,
    "created": 1585035085802,
    "state_id": 1,
    "class_id": 13,
    "_stateConditionRefs": [],
    "operations": [],
    "properties": [],
    "id": "5e79b74d6ec5ea28e5105c58"
}

Create an object with multiple parents

This example shows how to make an object with multiple parents. If the object has multiple parents, it acts as one object, but shows up under each parent in the hierarchy:

Object with multiple parents

Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/objects

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
"name": "Object with multiple parents",
    "parent_id": [
"62ea5dd6cd1c9856d0f55e9c",
"62e923ffb8ff53567ebda356",
"62d7e5d456d203149a080026"
]
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/objects";
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": "Object with multiple parents",
    "parent_id": [
"62ea5dd6cd1c9856d0f55e9c",
"62e923ffb8ff53567ebda356",
"62d7e5d456d203149a080026"
]
});

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/objects";
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": "Object with multiple parents",
    "parent_id": [
"62ea5dd6cd1c9856d0f55e9c",
"62e923ffb8ff53567ebda356",
"62d7e5d456d203149a080026"
]
});

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

login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/objects"
body = {
"name": "Object with multiple parents",
    "parent_id": [
"62ea5dd6cd1c9856d0f55e9c",
"62e923ffb8ff53567ebda356",
"62d7e5d456d203149a080026"
]
}

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

Response

{
    "name": "Object with multiple parents",
    "owner_id": "5e21b752308c3c66d64e072c",
    "object_groups": [],
    "geoposition": [],
    "child_ref_ids": [],
    "child_link_ids": [],
    "child_ids": [],
    "parent_id": [
        "62ea5dd6cd1c9856d0f55e9c",
        "62e923ffb8ff53567ebda356",
        "62d7e5d456d203149a080026"
    ],
    "weight": 1,
    "tags": [],
    "last_state_update": 1585035085802,
    "updated": 1585035085800,
    "created": 1585035085802,
    "state_id": 1,
    "class_id": 13,
    "_stateConditionRefs": [],
    "operations": [],
    "properties": [],
    "id": "5e79b74d6ec5ea28e5105c58"
}

Create an object using a discovery ID

If the field is specified in a request body, the method works as follows: if an object with the specified discovery ID doesn’t exist, a new object with this ID will be created. If an object with the specified discovery ID already exists, the object’s body will be updated.

In this example, the first request creates a new object with the name "Discovery ID Test." The second request, instead of creating a new object, edits an existing object with the same discovery ID.

First Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/objects

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "name": "Discovery ID Test",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/objects";
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": "Discovery ID Test",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
});

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/objects";
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": "Discovery ID Test",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
});

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

login = '...'
password = '...'
saymon_hostname = '...'
url = "http://" + saymon_hostname + "/node/api/objects"

body = {
    "name": "Discovery ID Test",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
}

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

Second Request

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/objects

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "name": "Discovery ID Test Edited",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/objects";
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": "Discovery ID Test Edited",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
});

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/objects";
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": "Discovery ID Test Edited",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
});

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

login = '...'
password = '...'
saymon_hostname = '...'
url = "http://" + saymon_hostname + "/node/api/objects"

body = {
    "name": "Discovery ID Test Edited",
    "parent_id": "62e923d8cf878556dcf522b7",
    "discovery_id": "Discovery ID Test Object"
}

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

Response

  • First Request

  • Second Request

{
    "id": "62ea7145b8ff53567ebda38d",
    "parent_id": [
        "62e923d8cf878556dcf522b7"
    ],
    "name": "Discovery ID Test",
    "discovery_id": "Discovery ID Test Object",
    "owner_id": "62c2f3ce80c8654892764d56",
    "updated": 1659531655003,
    "properties": [],
    "operations": [],
    "class_id": 13,
    "state_id": 1,
    "created": 1659531589533,
    "last_state_update": 1659531589533,
    "tags": [],
    "weight": 1,
    "child_ids": [],
    "child_link_ids": [],
    "child_ref_ids": [],
    "geoposition": [],
    "object_groups": []
}
{
    "id": "62ea7145b8ff53567ebda38d",
    "parent_id": [
        "62e923d8cf878556dcf522b7"
    ],
    "name": "Discovery ID Test Edited",
    "discovery_id": "Discovery ID Test Object",
    "owner_id": "62c2f3ce80c8654892764d56",
    "updated": 1659531655003,
    "properties": [],
    "operations": [],
    "class_id": 13,
    "state_id": 1,
    "created": 1659531589533,
    "last_state_update": 1659531589533,
    "tags": [],
    "weight": 1,
    "child_ids": [],
    "child_link_ids": [],
    "child_ref_ids": [],
    "geoposition": [],
    "object_groups": []
}

See Also