[comment]: # translation:outdated

[comment]: # ({e42e8a0a-e42e8a0a})
# 批量更新模板

[comment]: # ({/e42e8a0a-e42e8a0a})

[comment]: # ({76d86575-cf27d8f8})
### 描述

`object template.massupdate(object parameters)`

此方法允许同时替换或删除相关对象，并更新多个模板上的属性。

::: noteclassic
此方法仅适用于管理员和超级管理员用户类型。可以在用户角色设置中撤销调用该方法的权限。详情请阅 [User roles](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/76d86575-cf27d8f8})

[comment]: # ({c56226f4-1f7d5759})
### 参数

`(object)` 参数包含要更新的模板ID和要替换的模板对象。

该方法接受以下参数.

|参数|[类型](/manual/api/reference_commentary#data_types)|描述|
|---------|---------------------------------------------------|-----------|
|**templates**<br>(必须)|object/array|要更新的模版。<br><br>模版必须有已定义的`templateid`属性。|
|groups|object/array|用于替换模板所属的当前主机群组的主机群组。<br><br>主机群组必须有已定义的`groupid`属性。|
|macros|object/array|用户宏替换给定模板上的当前用户宏。|
|templates\_clear|object/array|取消链接并清除给定模板的模板。<br><br>模版必须有已定义的`templateid`属性。|
|templates\_link|object/array|替换当前链接的模板的模板。<br><br>模版必须有已定义的`templateid`属性。|

[comment]: # ({/c56226f4-1f7d5759})

[comment]: # ({dcba01c8-dcba01c8})
### 返回值

`(object)` 返回一个对象，该对象包含`templateids`属性下已更新模板的ID。

[comment]: # ({/dcba01c8-dcba01c8})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({new-d18b091c})
#### Unlinking a template

Unlink and clear template "10091" from the given templates.

[Request](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "templates_clear": [
            {
                "templateid": "10091"
            }
        ]
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10085",
            "10086"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-d18b091c})

[comment]: # ({03cd0f32-0ecefb75})
#### 替换主机群组

从给定模板中取消链接并清除模板“10091”。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "templates_clear": [
            {
                "templateid": "10091"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10085",
            "10086"
        ]
    },
    "id": 1
}
```

[comment]: # ({/03cd0f32-0ecefb75})

[comment]: # ({4fcc9622-5d283e35})
### 参阅

-   [更新模板](update)
-   [批量添加模板](massadd)
-   [主机组](/manual/api/reference/hostgroup/object#host_group)
-   [用户宏](/manual/api/reference/usermacro/object#hosttemplate_level_macro)

[comment]: # ({/4fcc9622-5d283e35})

[comment]: # ({b5f8dcd9-b5f8dcd9})
### 源码

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

[comment]: # ({/b5f8dcd9-b5f8dcd9})
