Set Favorites
Sets current user’s favorites.
If you need to set favorites of another user, use the Update User request.
Request
Body parameters
Favorites don’t have a fixed structure, so favorites may return a custom set of variables.
The recommended structure is described in the Favorites model.
Request body
Request body contains entities that you set as favorites.
This request overwrites the previous set of favorites. |
Favorites don’t have a fixed structure, so you can pass any parameters and use a custom format.
However, it’s recommended to use the structure is described in the Favorites model:
[
{
"name": "String", // Favorites collection name.
"objects": [
"String" // Object's ID.
],
"links": [
"String" // Link's ID.
],
"operations": [
{
"id": "String", // Operation's ID."
"entityType": Integer, // Type of the entity. It's equal to 1 for objects and 2 for links.
"entityId": "String" // ID of an entity to which the operation belongs.
}
],
"graphs": [
{
"metric": "String", // Metric name."
"entityType": Integer, // Type of the entity. It's equal to 1 for objects and 2 for links.,
"entityId": "String", // ID of an entity to which the metric belongs.
}
]
}
]
Example
Request
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/users/favorites
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
--d @- <<EOF [
{
"name": "My favorites",
"objects": [
"5e21b752308c3c66d64e072c",
"6315fc710f3d71351b6609c8"
],
"links": [
"5e4fc1c77915112ac209e53d",
"5c541db3347bb9002714d002"
],
"operations": [
{
"id": "5e21b85b308c3c66d64e07bc",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
},
{
"id": "5c541db3347bb9002714d003",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
}
],
"graphs": [
{
"metric": "stdout.m1",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "stdout.m2",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "TOTAL.bytesUsed",
"entityType": 1,
"entityId": "5c541dc5347bb9002714d17c",
}
]
}
]
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/users/favorites";
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": "My favorites",
"objects": [
"5e21b752308c3c66d64e072c",
"6315fc710f3d71351b6609c8"
],
"links": [
"5e4fc1c77915112ac209e53d",
"5c541db3347bb9002714d002"
],
"operations": [
{
"id": "5e21b85b308c3c66d64e07bc",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
},
{
"id": "5c541db3347bb9002714d003",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
}
],
"graphs": [
{
"metric": "stdout.m1",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "stdout.m2",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "TOTAL.bytesUsed",
"entityType": 1,
"entityId": "5c541dc5347bb9002714d17c",
}
]
}
]);
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/users/favorites";
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": "My favorites",
"objects": [
"5e21b752308c3c66d64e072c",
"6315fc710f3d71351b6609c8"
],
"links": [
"5e4fc1c77915112ac209e53d",
"5c541db3347bb9002714d002"
],
"operations": [
{
"id": "5e21b85b308c3c66d64e07bc",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
},
{
"id": "5c541db3347bb9002714d003",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
}
],
"graphs": [
{
"metric": "stdout.m1",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "stdout.m2",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "TOTAL.bytesUsed",
"entityType": 1,
"entityId": "5c541dc5347bb9002714d17c",
}
]
}
]);
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
url = "http://" + saymon_hostname + "/node/api/users/favorites"
body = [
{
"name": "My favorites",
"objects": [
"5e21b752308c3c66d64e072c",
"6315fc710f3d71351b6609c8"
],
"links": [
"5e4fc1c77915112ac209e53d",
"5c541db3347bb9002714d002"
],
"operations": [
{
"id": "5e21b85b308c3c66d64e07bc",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
},
{
"id": "5c541db3347bb9002714d003",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
}
],
"graphs": [
{
"metric": "stdout.m1",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "stdout.m2",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "TOTAL.bytesUsed",
"entityType": 1,
"entityId": "5c541dc5347bb9002714d17c",
}
]
}
]
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)
Response
[
{
"name": "My favorites",
"objects": [
"5e21b752308c3c66d64e072c",
"6315fc710f3d71351b6609c8"
],
"links": [
"5e4fc1c77915112ac209e53d",
"5c541db3347bb9002714d002"
],
"operations": [
{
"id": "5e21b85b308c3c66d64e07bc",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
},
{
"id": "5c541db3347bb9002714d003",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c"
}
],
"graphs": [
{
"metric": "stdout.m1",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "stdout.m2",
"entityType": 1,
"entityId": "5e21b752308c3c66d64e072c",
},
{
"metric": "TOTAL.bytesUsed",
"entityType": 1,
"entityId": "5c541dc5347bb9002714d17c",
}
]
}
]