Create Link Operation
Creates an operation in a link with the specified ID.
Request
HTTP Request
Permissions
Path parameters
Parameter | Type | Description |
---|---|---|
id | Stringrequired |
The ID of a link for which an operation should be created. |
Body parameters
This request uses the Operation model (except for id
field).
Note that the parameters
field is different for each operation type and subtype.
Request body
Type-specific parameters:
MQTT parameters
Filesystem script parameters
Repository script parameters
Plain text script parameters
Response
Returns the created operation in the JSON format (including its id
).
Examples
MQTT operation
This example creates a link operation that sends an MQTT message.
Request
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "MQTT Operation",
"description": "This is an the operation that sends an MQTT message",
"type": 1,
"popupResult": false
"parameters": {
"topic": "MQTT Topic",
"message": "MQTT Message Text"
}
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "MQTT Operation",
"description": "This is an the operation that sends an MQTT message",
"type": 1,
"popupResult": false
"parameters": {
"topic": "MQTT Topic",
"message": "MQTT Message Text"
}
});
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 linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "MQTT Operation",
"description": "This is an the operation that sends an MQTT message",
"type": 1,
"popupResult": false
"parameters": {
"topic": "MQTT Topic",
"message": "MQTT Message Text"
}
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations"
body = {
"name": "MQTT Operation",
"description": "This is an the operation that sends an MQTT message",
"type": 1,
"popupResult": False,
"parameters": {
"topic": "MQTT Topic",
"message": "MQTT Message Text"
}
}
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)
Response
File system script operation
This example creates a link operation that executes a script from the file system. In this example, the operation calls a script in the file /script_name.sh
with two arguments — Hello
and World
.
Request
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Filesystem Script",
"description": "Filesystem script description",
"type": 2,
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"type": "fileSystem",
"args": [
"Hello",
"World"
]
}
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Filesystem Script",
"description": "Filesystem script description",
"type": 2,
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"type": "fileSystem",
"args": [
"Hello",
"World"
]
}
});
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 linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Filesystem Script",
"description": "Filesystem script description",
"type": 2,
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"type": "fileSystem",
"args": [
"Hello",
"World"
]
}
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations"
body = {
"name": "Filesystem Script",
"description": "Filesystem script description",
"type": 2,
"popupResult": False,
"parameters": {
"path": "/script_name.sh",
"type": "fileSystem",
"args": [
"Hello",
"World"
]
}
}
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)
Response
Repository script operation
This example creates a link operation that executes a script from the repository.
Request
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Repository Script",
"description": "Script from repository",
"type": 2,
"popupResult": false,
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
"type": "scriptReference"
}
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Repository Script",
"description": "Script from repository",
"type": 2,
"popupResult": false,
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
"type": "scriptReference"
}
});
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 linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Repository Script",
"description": "Script from repository",
"type": 2,
"popupResult": false,
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
"type": "scriptReference"
}
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations"
body = {
"name": "Repository Script",
"description": "Script from repository",
"type": 2,
"popupResult": False,
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
"type": "scriptReference"
}
}
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)
Response
Plain text script operation
This example creates a link operation that executes a Bash script that prints "Hello World!" to the stdout.
Request
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Script Text",
"description": "Prints 'Hello World!'",
"popupResult": true,
"type": 2,
"parameters": {
"type": "scriptText",
"text": "echo 'Hello World!'"
}
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Script Text",
"description": "Prints 'Hello World!'",
"popupResult": true,
"type": 2,
"parameters": {
"type": "scriptText",
"text": "echo 'Hello World!'"
}
});
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 linkId = <...>
let path = "/node/api/links/" + linkId + "/operations";
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": "Script Text",
"description": "Prints 'Hello World!'",
"popupResult": true,
"type": 2,
"parameters": {
"type": "scriptText",
"text": "echo 'Hello World!'"
}
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations"
body = {
"name": "Script Text",
"description": "Prints 'Hello World!'",
"popupResult": True,
"type": 2,
"parameters": {
"type": "scriptText",
"text": "echo 'Hello World!'"
}
}
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)