Create Link

POST /node/api/links

Creates a link between two objects. Returns the new link in the JSON format.
Permissions: create-links | manage-links.

Request parameters

Body parameters

Parameter
Type
Description
source
string
required
The ID of a source object.
target
string
required
The ID of a target object.

Response description

...

Examples

Request example

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

Response example

1
{
2
"source": "5e79baae6ec5ea28e5105caa",
3
"target": "5e79bbe86ec5ea28e5105d04",
4
"owner_id": "5e21b752308c3c66d64e072c",
5
"weight": 1,
6
"tags": [],
7
"last_state_update": 1585053147047,
8
"updated": 1585053147046,
9
"created": 1585053147047,
10
"state_id": 1,
11
"class_id": 35,
12
"_stateConditionRefs": [],
13
"operations": [],
14
"properties": [],
15
"id": "5e79fddb6ec5ea28e5105f65"
16
}
Copied!
Last modified 1yr ago