Добавить пользовательский результат работы

Добавляет пользовательский результат список результатов работы.

Запрос

HTTP Запрос

PATCH /node/api/jobs/:id/results

Права

objectPermissions + (modify-objects | manage-objects)

Параметры пути

Параметр Тип Описание

id

String
обязательный

ID работы.

Тело запроса

Тело запроса содержит набор параметров, которые вы хотите включить в результат работы.

Пример запроса:

{
    "String property": "Value",
    "Integer property": 1234,
    "Boolean property": true,
    "Array property":[
        "Value",
        "Another Value"
    ]
}

Ответ

Тело ответа пустое.

Пример

Запрос

  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
job_id=<...>
url=https://$saymon_hostname/node/api/jobs/$job_id/results

curl -X PATCH $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "custom property": "some value",
    "another custom property": "another value"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let jobId = <...>
let path = "/node/api/jobs/" + jobId + "/results";
let auth = "Basic " + btoa(login + ":" + password);

let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", auth);

let data = JSON.stringify({
    "custom property": "some value",
    "another custom property": "another value"
});

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 jobId = <...>
let path = "/node/api/jobs/" + job_id + "/results";
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({
    "custom property": "some value",
    "another custom property": "another value"
});

req.write(data);
req.end();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
job_id = <...>

url = "http://" + saymon_hostname + "/node/api/jobs/" + job_id + "/results"

body = {
    "custom property": "some value",
    "another custom property": "another value"
}

response = requests.request("PATCH", url, json=body, auth=(login, password))
print(response.text)

Результат

При успешном выполнении запроса, в результатах заданной работы (массив results) будет добавлено новое значение:

{
    "description": {
        "stdout": "Hello World!",
        "exitCode": 0
    },
    "results": [
        {
            "payload": {
                "custom property": "some value",
                "another custom property": "another value"
            },
            "by": "62c2f3ce80c8654892764d56",
            "timestamp": 1658926668678
        }
        {
            "payload": {
                "pre-existing property": "pre-existing value"
            },
            "by": "62c2f3ce80c8654892764d56",
            "timestamp": 1658753182720
        }
    ],
    ...
    "id": "62de90b0b238aa0131bd3b8f"
}

Смотрите также