template.massadd

Description

object template.massadd(object **parameters**)

This method allows to simultaneously add multiple related objects to the given templates.

This method is only available to Admin and Super admin user types. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters containing the IDs of the templates to update and the objects to add to the templates.

The method accepts the following parameters.

ParameterTypeDescription
templates
(required)
object/arrayTemplates to be updated.

The templates must have the templateid property defined.
groupsobject/arrayHost groups to add the given templates to.

The host groups must have the groupid property defined.
hostsobject/arrayHosts and templates to link the given templates to.

The hosts must have the hostid property defined.
macrosobject/arrayUser macros to be created for the given templates.
templates_linkobject/arrayTemplates to link to the given templates.

The templates must have the templateid property defined.

Return values

(object) Returns an object containing the IDs of the updated templates under the templateids property.

Examples

Adding templates to a group

Add two templates to the host group “2”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massadd",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10085"
  8. },
  9. {
  10. "templateid": "10086"
  11. }
  12. ],
  13. "groups": [
  14. {
  15. "groupid": "2"
  16. }
  17. ]
  18. },
  19. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  20. "id": 1
  21. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10085",
  6. "10086"
  7. ]
  8. },
  9. "id": 1
  10. }

Linking a template to hosts

Link template “10073” to two hosts.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massadd",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10073"
  8. }
  9. ],
  10. "hosts": [
  11. {
  12. "hostid": "10106"
  13. },
  14. {
  15. "hostid": "10104"
  16. }
  17. ]
  18. },
  19. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  20. "id": 1
  21. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10073"
  6. ]
  7. },
  8. "id": 1
  9. }

See also

Source

CTemplate::massAdd() in ui/include/classes/api/services/CTemplate.php.