template.create

Description

object template.create(object/array templates)

This method allows to create new 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/array) Templates to create.

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

ParameterTypeDescription
groups
(required)
object/arrayHost groups to add the template to.

The host groups must have the groupid property defined.
tagsobject/arrayTemplate tags.
templatesobject/arrayTemplates to be linked to the template.

The templates must have the templateid property defined.
macrosobject/arrayUser macros to be created for the template.

Return values

(object) Returns an object containing the IDs of the created templates under the templateids property. The order of the returned IDs matches the order of the passed templates.

Examples

Creating a template

Create a template with tags and link two templates to this template.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.create",
  4. "params": {
  5. "host": "Linux template",
  6. "groups": {
  7. "groupid": 1
  8. },
  9. "templates": [
  10. {
  11. "templateid": "11115"
  12. },
  13. {
  14. "templateid": "11116"
  15. }
  16. ],
  17. "tags": [
  18. {
  19. "tag": "Host name",
  20. "value": "{HOST.NAME}"
  21. }
  22. ]
  23. },
  24. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  25. "id": 1
  26. }

Response:

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

Source

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