Set Object's State

PUT /node/api/objects/:id/state

Sets object's state.
Permissions: objectPermissions & (modify-objects | manage-objects).

Request parameters

Path parameters

Parameter
Type
Description
id
string
required
The ID or discovery ID of the object whose state must be set.

Response description

The response body contains the updated object in the JSON format.

Examples

Request examples

Bash
JavaScript
NodeJS
Python
1
login=<...>
2
password=<...>
3
saymon_hostname=<...>
4
object_id=<...>
5
url=https://$saymon_hostname/node/api/objects/$object_id/state
6
7
curl -X PUT $url -u $login:$password \
8
-H "Content-Type: application/json" \
9
-d @- <<EOF
10
{
11
"state_id": 4
12
}
13
EOF
Copied!
1
let login = <...>
2
let password = <...>
3
let saymonHostname = <...>
4
let objectId = <...>
5
let path = "/node/api/objects/" + objectId + "/state";
6
let auth = "Basic " + btoa(login + ":" + password);
7
8
let headers = new Headers();
9
headers.append("Authorization", auth);
10
headers.append("Content-Type", "application/json");
11
12
let data = JSON.stringify({
13
"state_id": 4
14
});
15
16
let requestOptions = {
17
method: "PUT",
18
headers: headers,
19
body: data
20
};
21
22
fetch(saymonHostname + path, requestOptions)
23
.then(response => response.text())
24
.then(result => console.log(result))
25
.catch(error => console.log("error", error));
Copied!
1
const http = require("http");
2
3
let login = <...>
4
let password = <...>
5
let saymonHostname = <...>
6
let objectId = <...>
7
let path = "/node/api/objects/" + objectId + "/state";
8
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
9
10
let options = {
11
"method": "PUT",
12
"hostname": saymonHostname,
13
"headers": {
14
"Authorization": auth,
15
"Content-Type": "application/json"
16
},
17
"path": path
18
};
19
20
let req = http.request(options, function (res) {
21
let chunks = [];
22
23
res.on("data", function (chunk) {
24
chunks.push(chunk);
25
});
26
27
res.on("end", function (chunk) {
28
let body = Buffer.concat(chunks);
29
console.log(body.toString());
30
});
31
32
res.on("error", function (error) {
33
console.error(error);
34
});
35
});
36
37
let data = JSON.stringify({
38
"state_id": 4
39
});
40
41
req.write(data);
42
req.end();
Copied!
1
import requests
2
3
login = <...>
4
password = <...>
5
saymon_hostname = <...>
6
object_id = <...>
7
url = "https://" + saymon_hostname + "/node/api/objects/" + \
8
object_id + "/state";
9
10
body = {
11
"state_id": 4
12
}
13
14
response = requests.request("PUT", url, json=body, auth=(login, password))
15
print(response.text)
Copied!

Response example

1
{
2
"entityId": "5e21b85b308c3c66d64e07d2",
3
"entityType": 1,
4
"body": {
5
"id": "5e21b85b308c3c66d64e07d2",
6
"name": "CPU",
7
"discovery_id": "192.168.1.82-CPU",
8
"object_groups": [],
9
"geoposition": [],
10
"child_ref_ids": [],
11
"child_link_ids": [],
12
"child_ids": [],
13
"parent_id": "5e21b85b308c3c66d64e07bc",
14
"weight": 1,
15
"tags": [],
16
"last_state_update": 1585045998154,
17
"updated": 1583916836283,
18
"created": 1579268187099,
19
"state_id": 4,
20
"class_id": 4,
21
"_stateConditionRefs": [],
22
"operations": [],
23
"properties": [],
24
"client_data": "...",
25
"manual_state": null,
26
"owner_id": "5e21b752308c3c66d64e072c"
27
}
28
}
Copied!