[comment]: # translation:outdated

[comment]: # ({66c5a546-66c5a546})
# host.massadd

[comment]: # ({/66c5a546-66c5a546})

[comment]: # ({d60cc608-55030171})
### 描述

`object host.massadd(object parameters)`

此方法允许将多个相关的 objects 同时添加到所有给定的 主机。

::: noteclassic
此方法仅适用于 *管理员* 和 *超级管理员* 用户类型。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见 [User
roles](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/d60cc608-55030171})

[comment]: # ({abd953a7-c25e2be4})
### 参数

(object) 参数包含要传递给 update 的 主机 的 ID
添加到所有 主机 的 objects。

该方法接受以下参数。

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| hosts | object/array | [Hosts](/manual/api/reference/host/object) 需要更新。<br><br>该 主机 必须仅定义 `hostid` 属性。<br><br>[参数行为](/manual/api/reference_commentary#参数行为)：<br>- *必填* |
| groups | object/array | [Host groups](/manual/api/reference/hostgroup/object) 添加到给定的 主机。<br><br>必须只为 主机 组定义 `groupid` 属性。
| interfaces | object/array | 为给定的 主机 创建 [Host interfaces](/manual/api/reference/hostinterface/object)。 |
| macros | object/array | 为给定的 主机 创建 [User macros](/manual/api/reference/usermacro/object)。 |
| templates | object/array | [Templates](/manual/api/reference/template/object) 用于链接到给定的 主机。<br><br>模板必须仅定义 `templateid` 属性。

[comment]: # ({/abd953a7-c25e2be4})

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

`(object)` 返回一个 object，其中包含更新后的 主机 的 ID，
这些 ID 位于 `hostids` 属性下。

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

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

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

[comment]: # ({b2ef6e4f-453a1298})
#### 添加宏

向两个 主机 添加两个新的宏。

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


```json
{
    "jsonrpc": "2.0",
    "method": "host.massadd",
    "params": {
        "hosts": [
            {
                "hostid": "10160"
            },
            {
                "hostid": "10167"
            }
        ],
        "macros": [
            {
                "macro": "{$TEST1}",
                "value": "MACROTEST1"
            },
            {
                "macro": "{$TEST2}",
                "value": "MACROTEST2",
                "description": "Test description"
            }
        ]
    },
    "id": 1
}
```
响应：


```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10160",
            "10167"
        ]
    },
    "id": 1
}
```

[comment]: # ({/b2ef6e4f-453a1298})

[comment]: # ({ae4115e5-ae4115e5})
### 另请参阅

-   [host.update](update)
-   [主机组](/manual/api/reference/hostgroup/object#主机组)
-   [模板](/manual/api/reference/template/object#模板)
-   [用户宏-object](/manual/api/reference/usermacro/object#用户宏-object)
-   [主机接口](/manual/api/reference/hostinterface/object#主机接口)

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

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

`CHost::massAdd()` 在 *ui/include/classes/api/services/CHost.php* 中。

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