Обновить операцию связи
Запрос
Параметры пути
Параметр | Тип | Описание |
---|---|---|
link_id |
String |
ID связи. |
op_id |
String |
ID операции. |
Параметры тела запроса
Этот запрос использует модель Операция за исключением нескольких полей. Поле parameters
отличается для каждого типа и подтипа операции.
Во время обновления нельзя изменить тип и подтип операции. |
Поля, которые можно обновить
Поле | Тип | Описание |
---|---|---|
name |
String |
Имя операции. |
description |
String |
Описание операции |
popupResult |
Boolean |
Показывать результаты операции во всплывающем окне в веб-интерфейсе |
parameters.message |
String |
MQTT сообщение. Этот параметр должен быть определён только для типа MQTT сообщение. |
parameters.topic |
String |
MQTT топик. Этот параметр должен быть определён только для типа MQTT сообщение. |
parameters.path |
String |
Путь до скрипта. Этот параметр должен быть определён только для подтипа |
parameters.args |
Array<String> |
Массив аргументов скрипта. Этот параметр должен быть определён только для подтипа |
parameters.ref |
String |
ID скрипта. Этот параметр должен быть определён только для подтипа |
parameters.text |
String |
Исходный код скрипта. Этот параметр должен быть определён только для подтипа |
Тело запроса
{
"name": "New name for the operation", "description": "The updated description of the link operation",
"popupResult": false,
"parameters": {
// Type-specific parameters
}
}
Параметры, специфичные для операции:
Параметры MQTT
{
"name": "MQTT",
...
"type": 1,
"parameters": {
"topic": "MQTT Topic",
"message": "MQTT Message Text"
}
}
Параметры скрипта из файловой системы
{
"name": "Filesystem Script",
...
"type": 2,
"parameters": {
"type": "fileSystem",
"path": "/script_name.sh",
"args": [
"Hello",
"World"
]
}
}
Параметры скрипта из репозитория
{
"name": "Repository Script",
...
"type": 2,
"parameters": {
"type": "scriptReference",
"ref": "5ecfc1e06d9341263ceaaeb3" // Script ID
}
}
Параметры текстового скрипта
{
"name": "Plain Text Script",
...
"type": 2,
"parameters": {
"type": "scriptText",
"text": "echo 'Hello World!'"
}
}
Примеры
MQTT operation
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
operation_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations/$operation_id
curl -X PATCH $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Updated MQTT Operation",
"parameters": {
"topic": "New MQTT Topic",
"message": "New MQTT Message Text"
},
"description": "Updated Description",
"popupResult": false,
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let operationId = <...>
let path = "/node/api/objects/" + objectId + "/operations/" + operationId;
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": "Updated MQTT Operation",
"parameters": {
"topic": "New MQTT Topic",
"message": "New MQTT Message Text"
},
"description": "Updated Description",
"popupResult": false,
});
let requestOptions = {
method: "PATCH",
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 operationId = <...>
let path = "/node/api/links/" + linkId + "/operations/" + operationId;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "PATCH",
"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": "Updated MQTT Operation",
"parameters": {
"topic": "New MQTT Topic",
"message": "New MQTT Message Text"
},
"description": "Updated Description",
"popupResult": false,
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
operation_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations/" + operation_id
body = {
"name": "Updated MQTT Operation",
"parameters": {
"topic": "New MQTT Topic",
"message": "New MQTT Message Text"
},
"description": "Updated Description",
"popupResult": False,
}
response = requests.request("PATCH", url, json=body, auth=(login, password))
print(response.text)
Ответ
{
"name": "Updated MQTT Operation",
"parameters": {
"topic": "New MQTT Topic",
"message": "New MQTT Message Text"
},
"description": "Updated Description",
"type": 1,
"popupResult": false,
"id": "62d9331aac866e4fcc1f21c0"
}
Операция скрипта файловой системы
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
operation_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations/$operation_id
curl -X PATCH $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Updated Filesystem Script",
"description": "Updated description",
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"args": [
"Hello",
"World"
]
}
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let operationId = <...>
let path = "/node/api/objects/" + objectId + "/operations/" + operationId;
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": "Updated Filesystem Script",
"description": "Updated description",
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"args": [
"Hello",
"World"
]
}
});
let requestOptions = {
method: "PATCH",
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 operationId = <...>
let path = "/node/api/links/" + linkId + "/operations/" + operationId;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "PATCH",
"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": "Updated Filesystem Script",
"description": "Updated description",
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"args": [
"Hello",
"World"
]
}
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
operation_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations/" + operation_id
body = {
"name": "Updated Filesystem Script",
"description": "Updated description",
"popupResult": False,
"parameters": {
"path": "/script_name.sh",
"args": [
"Hello",
"World"
]
}
}
response = requests.request("PATCH", url, json=body, auth=(login, password))
print(response.text)
Ответ
{
"name": "Updated Filesystem Script",
"description": "Updated description",
"type": 2,
"popupResult": false,
"parameters": {
"path": "/script_name.sh",
"type": "fileSystem",
"args": [
"Hello",
"World"
]
},
"id": "62d95c18b238aa0131bd3b64"
}
Операция со скриптом из репозитория
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
operation_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations/$operation_id
curl -X PATCH $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Updated Repository Script",
"description": "Updated Script from repository",
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
},
"popupResult": True
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let operationId = <...>
let path = "/node/api/objects/" + objectId + "/operations/" + operationId;
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": "Updated Repository Script",
"description": "Updated Script from repository",
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
},
"popupResult": True
});
let requestOptions = {
method: "PATCH",
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 operationId = <...>
let path = "/node/api/links/" + linkId + "/operations/" + operationId;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "PATCH",
"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": "Updated Repository Script",
"description": "Updated Script from repository",
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
},
"popupResult": True
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
operation_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations/" + operation_id
body = {
"name": "Updated Repository Script",
"description": "Updated Script from repository",
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
},
"popupResult": True
}
response = requests.request("PATCH", url, json=body, auth=(login, password))
print(response.text)
Ответ
{
"name": "Updated Repository Script",
"parameters": {
"ref": "5ecfc1e06d9341263ceaaeb3",
"type": "scriptReference"
},
"description": "Updated Script from repository",
"type": 2,
"popupResult": false,
"id": "62d9353d60d9d84f03997b22"
}
Операция с текстовым скриптом
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
operation_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/operations/$operation_id
curl -X PATCH $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "Updated Plain Text Link Script",
"description": "Updated plain text script",
"parameters": {
"text": "echo \"Updated operation!\""
},
"popupResult": True
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let operationId = <...>
let path = "/node/api/objects/" + objectId + "/operations/" + operationId;
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": "Updated Plain Text Link Script",
"description": "Updated plain text script",
"parameters": {
"text": "echo \"Updated operation!\""
},
"popupResult": True
});
let requestOptions = {
method: "PATCH",
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 operationId = <...>
let path = "/node/api/links/" + linkId + "/operations/" + operationId;
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
"method": "PATCH",
"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": "Updated Plain Text Link Script",
"description": "Updated plain text script",
"parameters": {
"text": "echo \"Updated operation!\""
},
"popupResult": True
});
req.write(data);
req.end();
import requests
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
operation_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/operations/" + operation_id
body = {
"name": "Updated Plain Text Link Script",
"description": "Updated plain text script",
"parameters": {
"text": "echo \"Updated operation!\""
},
"popupResult": True
}
response = requests.request("PATCH", url, json=body, auth=(login, password))
print(response.text)