Get All Links
Returns a list of all links in the system.
Note
This request doesn't return all fields of links by default. Check the Response section for more information.
Request
HTTP Request
Permissions
Path parameters
No parameters required.
Query parameters
Parameter | Type | Description |
---|---|---|
fields | String | A comma-separated list of links' fields to be retrieved. See the Link model for all fields. |
Request body
The request body is empty.
Response
The response contains an array of all links in the system in the JSON format.
Fields that are included in the response by default:
Field | Type | Description |
---|---|---|
id | String | Link's ID. Always returned. |
class_id | Integer | Link's Class ID. |
source | String | Link's source object. |
target | String | Link's target object. |
source_name | String | Name of the source object. |
target_name | String | Name of the target object. |
state_id | Integer | ID of the link's current state. |
last_state_update | Integer | Timestamp of the last state change. |
You can get any fields from a link by specifying them in the fields
query parameter. In this case, only specified fields and the link's id
will be included in the response. See the Link model for a list of all possible fields.
Examples
Get default fields
Get a default set of fields for every link in the system.
Request
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/links";
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Authorization", auth);
let requestOptions = {
method: "GET",
headers: headers
};
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/links";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Authorization": auth
},
"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);
});
});
req.end();
Response
[
{
"class_id": 35,
"source": "56658fd721eed1df4a9ba5ef",
"state_id": 3,
"target": "566965ff6fddd44f472423ff",
"last_state_update": 1660168711520,
"source_name": "source obj",
"target_name": "target obj",
"id": "5669660b6fddd44f47242401"
},
{
"class_id": 35,
"source": "567030ad73c5248568ce7728",
"state_id": 3,
"target": "56702ff073c5248568ce771d",
"last_state_update": 1660168703038,
"source_name": "source obj",
"target_name": "target obj",
"id": "567031be73c5248568ce7733"
},
{
"class_id": 35,
"source": 127,
"state_id": 9,
"target": 112,
"last_state_update": null,
"source_name": "source obj",
"target_name": "target obj",
"id": "56fce71063c02bcb447943c6"
}
...
]
Get specific fields
Specify the fields to retrieve during the request.
This example returns only source
and target
fields from the default set, and a properties
array that isn't included by default. Note that the id
field isn't explicitly set in the query parameters, but is returned anyway.
Request
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/links?fields=source,target,properties"
let auth = "Basic " + btoa(login + ":" + password)
var myHeaders = new Headers();
myHeaders.append("Authorization", auth);
let requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
let http = require('follow-redirects').http;
let fs = require('fs');
let saymonHostname = <...>
let login = <...>;
let password = <...>;
let auth = 'Basic ' + Buffer.from(login + ':' + password).toString('base64');
let options = {
'method': 'GET',
'hostname': saymonHostname,
'path': '/node/api/links?fields=source,target,properties',
'headers': {
'Authorization': auth
},
'maxRedirects': 20
};
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);
});
});
req.end();