template.create

描述

object template.create(object/array templates)

此方法允许create新模板。

此方法仅对管理员(Admin)超级管理员(Super admin)用户类型可用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见User roles

参数

(object/array) 要创建的模板。

除了标准模板属性之外,该方法还接受以下参数。

Parameter Type Description
groups object/array 要将模板添加到的模板组

模板组只能定义 groupid 属性。

参数行为:
- required
tags object/array 要创建的模板标签
templates object/array 要链接到该模板的模板

这些模板只能定义 templateid 属性。
macros object/array 要为该模板创建的用户宏

返回值

(object) 返回一个 object,其中包含在 templateids 属性下列出的已创建模板的 ID。返回的 ID 顺序与传入的模板顺序一致。

示例

创建模板

创建一个带有标签的模板,并将两个模板链接到此模板。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.create",
    "params": {
        "host": "Linux template",
        "groups": {
            "groupid": 1
        },
        "templates": [
            {
                "templateid": "11115"
            },
            {
                "templateid": "11116"
            }
        ],
        "tags": [
            {
                "tag": "host-name",
                "value": "{HOST.NAME}"
            }
        ]
    },
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "11117"
        ]
    },
    "id": 1
}

来源

CTemplate::create() 在 ui/include/classes/api/services/CTemplate.php 中。