Skip to content

Create Link Operation

Creates an operation in a link with the specified ID.

Request

HTTP Request

POST /node/api/links/:id/operations

Permissions

linkPermissions & manage-links & manage-operations

Path parameters

Parameter Type Description
id String
required
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

{
    "name": "Name of the link operation",
    "description": "The description of the link operation",
    "type": 1,      // The type of the operation. 1 is an MQTT operation, 2 is program/script operation
    "popupResult": false
    "parameters": {
        // Type-specific parameters
    }
}

Type-specific parameters:

MQTT parameters
{
    "name": "MQTT",
    ...
    "type": 1,
    "parameters": {
        "topic": "MQTT Topic",
        "message": "MQTT Message Text"
    }
}
Filesystem script parameters
{
    "name": "Filesystem Script",
    ...
    "type": 2,
    "parameters": {
        "type": "fileSystem",
        "path": "/script_name.sh",
        "args": [
            "Hello",
            "World"
        ]
    }
}
Repository script parameters
{
    "name": "Repository Script",
    ...
    "type": 2,
    "parameters": {
        "type": "scriptReference",
        "ref": "5ecfc1e06d9341263ceaaeb3"   // Script ID
    }
}
Plain text script parameters
{
    "name": "Plain Text Script",
    ...
    "type": 2,
    "parameters": {
        "type": "scriptText",
        "text": "echo 'Hello World!'"
    }
}

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 examples

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 example

{
    "name": "MQTT",
    "parameters": {
        "topic": "MQTT Topic",
        "message": "MQTT Message Text"
    },
    "description": "MQTT Description",
    "type": 1,
    "popupResult": false,
    "id": "62d9331aac866e4fcc1f21c0"
}

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 examples

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 example

{
    "name": "Filesystem Script",
    "description": "Filesystem script description",
    "type": 2,
    "popupResult": false,
    "parameters": {
        "path": "/script_name.sh",
        "type": "fileSystem",
        "args": [
            "Hello",
            "World"
        ]
    },
    "id": "62d95c18b238aa0131bd3b64"
}

Repository script operation

This example creates a link operation that executes a script from the repository.

Request examples

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 example

{
    "name": "Repository Script",
    "parameters": {
        "ref": "5ecfc1e06d9341263ceaaeb3",
        "type": "scriptReference"
    },
    "description": "Script from repository",
    "type": 2,
    "popupResult": false,
    "id": "62d9353d60d9d84f03997b22"
}

Plain text script operation

This example creates a link operation that executes a Bash script that prints "Hello World!" to the stdout.

Request examples

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)

Response example

{
    "name": "Script Text",
    "description": "Prints 'Hello World!'",
    "popupResult": true,
    "type": 2,
    "parameters": {
        "type": "scriptText",
        "text": "echo 'Hello World!'"
    },
    "id": "62d8473456d203149a08007e"
}