[comment]: # translation:outdated

[comment]: # ({8c618db1-8c618db1})
# 批量添加

[comment]: # ({/8c618db1-8c618db1})

[comment]: # ({644f677f-399b9834})
### 描述

`object template.massadd(object parameters)`

该方法允许同时将多个相关对象添加到给定的模板中。

::: noteclassic
这个方法只有 *管理员* 和 *超级管理员* 两个用户类型可用。可以在用户角色设置中撤销调用该方法的权限。 查看 [User
roles](/manual/web_interface/frontend_sections/users/user_roles)获取更多信息。
:::

[comment]: # ({/644f677f-399b9834})

[comment]: # ({01c6953d-4167b841})
### 参数

`(object)` 参数包含要更新的模板的ID以及要添加到模板中的对象。

这个方法接受下列参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|--|--|------|
|templates|object/array|要更新的[模版](/manual/api/reference/template/object) <br><br>这些模板必须只定义了 `templateid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#参数行为):<br>- *必需*|
|groups|object/array|将给定的模版添加到[模版组](/manual/api/reference/templategroup/object)。<br><br>这些模板必须只定义了 `groupid` 属性。|
|macros|object/array|要为给定模板创建的[用户宏](/manual/api/reference/usermacro/object) 。|
|templates\_link|object/array|要链接到给定模版的[模版](/manual/api/reference/template/object) 。<br><br>这些模板必须只定义了 `templateid` 属性。|

[comment]: # ({/01c6953d-4167b841})

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

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

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

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

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

[comment]: # ({9ee15989-f8fe44e4})
#### 将一个模板组链接到模板

将模板组 "2" 添加到两个模板中。

[请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ]
    },
    "id": 1
}
```

响应:

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

[comment]: # ({/9ee15989-f8fe44e4})

[comment]: # ({87e8784f-7dbed7e5})
#### 将两个模板链接到一个模板

将模板 "10106" 和 "10104" 链接到模板 "10073"。

[请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10073"
            }
        ],
        "templates_link": [
            {
                "templateid": "10106"
            },
            {
                "templateid": "10104"
            }
        ]
    },
    "id": 1
}
```

响应:

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

[comment]: # ({/87e8784f-7dbed7e5})

[comment]: # ({ddd17552-bd8dd370})
### 参阅

-   [更新](update)
-   [主机](/manual/api/reference/host/object#主机)
-   [模版组](/manual/api/reference/templategroup/object#模版组)
-   [用户宏](/manual/api/reference/usermacro/object#主机宏)

[comment]: # ({/ddd17552-bd8dd370})

[comment]: # ({2f7abcb1-2f7abcb1})
### 来源

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

[comment]: # ({/2f7abcb1-2f7abcb1})
