template.update

Description

object template.update(object/array **templates**)

This method allows to update existing templates.

Parameters

(object/array) Template properties to be updated.

The templateid property must be defined for each template, all other properties are optional. Only the given properties will be updated, all others will remain unchanged.

Additionally to the standard template properties, the method accepts the following parameters.

ParameterTypeDescription
groupsobject/arrayHost groups to replace the current host groups the templates belong to.

The host groups must have the groupid property defined.
tagsobject/arrayTemplate tags to replace the current template tags.
hostsobject/arrayHosts and templates to replace the ones the templates are currently linked to.

Both hosts and templates must use the hostid property to pass an ID.
macrosobject/arrayUser macros to replace the current user macros on the given templates.
templatesobject/arrayTemplates to replace the currently linked templates. Templates that are not passed are only unlinked.

The templates must have the templateid property defined.
templates_clearobject/arrayTemplates to unlink and clear from 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

Renaming a template

Rename the template to “Template OS Linux”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.update",
  4. "params": {
  5. "templateid": "10086",
  6. "name": "Template OS Linux"
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

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

Updating template tags

Replace all template tags with a new one.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.update",
  4. "params": {
  5. "templateid": "10086",
  6. "tags": [
  7. {
  8. "tag": "Host name",
  9. "value": "{HOST.NAME}"
  10. }
  11. ]
  12. },
  13. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  14. "id": 1
  15. }

Response:

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

Source

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