Skip to content

Run Bulk Operation for Objects

Runs a bulk operation for all objects that match a specified search criteria.

Request

HTTP Request

POST /node/api/bulk/objects

Permissions

run-bulks & manage-objects

Path parameters

No parameters required.

Body parameters

The request body consists of two parts — search and bulk. search describes the search criteria for objects. bulk describes operations that would be performed on the objects that fit the search criteria.

{
    "search": {
        ...
    },
    "bulk": [
        {
            ...
        },
        {
            ...
        }
        ...
    ]
}

This request uses the same search criteria as the Search Objects request to find the objects to perform the bulk operation on.

All search parameters are optional. If you set no parameters, all objects in the systems will be returned.

Bulk

The bulk variable stores the information about the operation that will be performed on the selected objects.

Parameter Type Description
modify Object The object's parameters to modify. See the Object to see all parameters that you can modify.
properties.createOrModify Object The properties to modify. Properties include custom properties, AgentId, TaskPeriodValue, TaskPeriodUnit.
stateConditions Object The State Conditions to modify.
stateTriggers Object The State Triggers to modify.
incidentConditions Object The Incident Conditions to modify.

Request body

{
    "search": {
        // Search criteria
    },
    "bulk": [
        {
            // Operation
        },
        {
            // Operation
        }
        ...
    ]
}

Response

Response contains the ID of the bulk operation and its status:

{
    "bulkId": "079b3102-c326-4dd7-bf48-a945232b32d6",
    "finished": false
}

Example

This example adds a new property to all objects named "CPU" that have a specified parent.

Request

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/bulk/objects

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    --d @- <<EOF {
    "search": {
        "name": {
            "$regex": "^CPU$",
            "$options": "i"
        },
        "parent_id": "62d7e58056d203149a08001b"
    },
    "bulk": [
        {
            "properties.createOrModify": {
                "name": "New Property",
                "value": "value",
                "type_id": 1
            }
        }
    ]
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/bulk/objects";
let auth = "Basic " + btoa(login + ":" + password);

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

let data = JSON.stringify({
    "search": {
        "name": {
            "$regex": "^CPU$",
            "$options": "i"
        },
        "parent_id": "62d7e58056d203149a08001b"
    },
    "bulk": [
        {
            "properties.createOrModify": {
                "name": "New Property",
                "value": "value",
                "type_id": 1
            }
        }
    ]
});

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 path = "/node/api/bulk/objects";
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({
    "search": {
        "name": {
            "$regex": "^CPU$",
            "$options": "i"
        },
        "parent_id": "62d7e58056d203149a08001b"
    },
    "bulk": [
        {
            "properties.createOrModify": {
                "name": "New Property",
                "value": "value",
                "type_id": 1
            }
        }
    ]
});

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

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

url = "http://" + saymon_hostname + "/node/api/bulk/objects"

body = {
    "search": {
        "name": {
            "$regex": "^CPU$",
            "$options": "i"
        },
        "parent_id": "62d7e58056d203149a08001b"
    },
    "bulk": [
        {
            "properties.createOrModify": {
                "name": "New Property",
                "value": "value",
                "type_id": 1
            }
        }
    ]
}

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

Response

{
    "bulkId": "079b3102-c326-4dd7-bf48-a945232b32d6",
    "finished": false
}

See Also