Skip to content

Get Job by Object/Link IDs

Returns jobs history for the specified object or link. The user can specify the time frame to show only those jobs that fall within it.

Warning

This request returns jobs related to either links or objects, but not both at the same time.

Info

If the requested job is related to the link, the user must have permission to access the link's source and target objects. See the Link Model for more info.

Request

HTTP Request

POST /node/api/jobs

Permissions

objectPermissions, linkPermissions.

Path parameters

No parameters required.

Body parameters

Parameter Type Description
links String The IDs of the links from which jobs are needed.
objects String The IDs of the objects from which jobs are needed.
from Integer
optional
Timestamp for the beginning of the time period.
to Integer
optional
Timestamp for the end of the time period.

Request body

This request returns jobs related to either links or objects, but not both at the same time. To get the job history for objects, use the objects parameter:

{
    "objects": [
        "<object_id_1>",
         ... , 
        "<object_id_n>"
        ],
    "from": <timestamp>,
    "to": <timestamp>
}

To get the job history for links, use the links parameter:

{
    "links": [
        "<link_id_1>",
         ... , 
        "<object_id_n>"
        ],
    "from": <timestamp>,
    "to": <timestamp>
}

Note that the time frame is optional, so you can omit from and to paramteres. In this case, this request returns all jobs generated by the specified objects/links:

{
    "objects": [
        "<object_id_1>",
         ... , 
        "<object_id_n>"
        ]
}
{
    "links": [
        "<link_id_1>",
         ... , 
        "<object_id_n>"
        ]
}

Response

This request uses the Job model (except the owner_type parameter).

Example

Request

login=<...>
password=<...>
saymon_hostname=<...>
url=http://$saymon_hostname/node/api/jobs

curl -L -X POST '$url' \
-u $login:$password \
-H 'Content-Type: application/json' \
-d '{
"objects":["<object_id_1>", ... , "<object_id_n>"],
"from":<timestamp>,
"to":<timestamp>
}'
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/jobs"
let auth = "Basic " + btoa(login + ":" + password)
let myHeaders = new Headers()

myHeaders.append("Authorization", auth);
myHeaders.append("Content-Type", "application/json");

let raw = JSON.stringify({
  "objects":["<object_id_1>", ... , "<object_id_n>"],
  "from":<timestamp>,
  "to":<timestamp>
});

let requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch(saymonHostname + path, requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
let http = require('follow-redirects').http;
let fs = require('fs');
let saymonHostname = <...>;
let login = <...>;
let password = <...>;
let auth = 'Basic ' + Buffer.from(login + ':' + password).toString('base64');

let options = {
  'method': 'POST',
  'hostname': saymonHostname,
  'path': '/node/api/jobs',
  'headers': {
    'Authorization': auth,
    'Content-Type': 'application/json'
  },
  'maxRedirects': 20
};

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 postData = JSON.stringify({
"objects":["<object_id_1>", ... , "<object_id_n>"],
"from":<timestamp>,
"to":<timestamp>
});

req.write(postData);

req.end();
import requests

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

url = 'http://' + saymon_hostname + '/node/api/jobs'

payload = {
    'objects':[
        '<object_id_1>',
        ... ,
        '<object_id_n>'
    ],
    'from':<timestamp>,
    'to':<timestamp>
}

headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, json=payload, auth=(login, password))

print(response.text)

Response

This example returns three jobs. The first two ("MQTT Operation" and "Script Operation") were manually executed by a user. The "Script Operation" job has two deferred results added by a user. The third — "State Change Script Operation" — was executed automatically on state change. The process_meta.triggerStates array lists states that can trigger this operation.

{
    "description": {
        "topic": "Test MQTT Operation",
        "message": "Message Text"
    },
    "results": [],
    "operation_id": "62de8eed361a5d7ec2768057",
    "owner_id": "62d7e5e456d203149a080038",
    "user_id": "62c2f3ce80c8654892764d56",
    "timestamp": 1658933295101,
    "process_meta": null,
    "operation": {
        "name": "MQTT Operation"
    },
    "id": "62e1502fda304c7f95cc52b7"
},
{
    "description": {
        "stdout": "Hello World!",
        "exitCode": 0
    },
    "results": [
        {
            "payload": {
                "parameter": "some value"
            },
            "by": "62c2f3ce80c8654892764d56",
            "timestamp": 1658926668678
        },
        {
            "payload": {
                "another parameter": "another value"
            },
            "by": "62c2f3ce80c8654892764d56",
            "timestamp": 1658974127721
        },
    ],
    "operation_id": "62de8f0cda304c7f95cc5252",
    "owner_id": "62d7e5e456d203149a080038",
    "user_id": "62c2f3ce80c8654892764d56",
    "timestamp": 1658974127800,
    "process_meta": null,
    "operation": {
        "name": "Script Operation"
    },
    "id": "62e1efafda304c7f95cc52c1"
},
{
    "description": {
        "stdout": "State Changed!",
        "exitCode": 0
    },
    "results": [],
    "operation_id": "62de8f0cda304c7f95cc5252",
    "owner_id": "62d7e5e456d203149a080038",
    "user_id": "",
    "timestamp": 1658975076372,
    "process_meta": {
        "triggerStates": [
            3,
            4,
            "58ff5f454815650157a6a62f"
        ]
    },
    "operation": {
        "name": "State Change Script Operation"
    },
    "id": "62e1f3641620fd7f489ccc59"
}

See Also