[comment]: # translation:outdated

[comment]: # ({2ed6e81f-2ed6e81f})
# 更新主机宏

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

[comment]: # ({692ab729-23e3a148})
### 描述

`object usermacro.update(object/array hostMacros)`

此方法用于更新现有的主机宏.

::: noteclassic
此方法只有*Admin(管理员)* 和 *Super admin(超级管理员)* 用户可用.可以在用户角色设置中撤销调用该方法的权限.更多信息请查看 [User roles](/manual/web_interface/frontend_sections/administration/user_roles).
:::

[comment]: # ({/692ab729-23e3a148})

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

`(object/array)` 需要更新的[Host macro properties](object#主机宏) .

每个主机宏必须定义 `hostmacroid` 参数, 其他参数均为可选的. 只有通过的属性才会被更新，其他属性保持不变.

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

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

`(object)` 返回包含 `hostmacroids` 属性（其中包含被更新主机宏的ID）的对象.

[comment]: # ({/5e19fc38-5e19fc38})

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

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

[comment]: # ({99fbab98-bc8ce678})
#### 更改一个主机宏的值

更改一个主机宏"public"的值.

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "usermacro.update",
    "params": {
        "hostmacroid": "1",
        "value": "public"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

返回:

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

[comment]: # ({/99fbab98-bc8ce678})

[comment]: # ({new-129f453e})
#### Change macro value that was created by discovery rule

Convert discovery rule created "automatic" macro to "manual" and change its value to "new-value".

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "usermacro.update",
    "params": {
        "hostmacroid": "1",
        "value": "new-value",
        "automatic": "0"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "hostmacroids": [
            "1"
        ]
    },
    "id": 1
}
```

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

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

CUserMacro::update() in
*ui/include/classes/api/services/CUserMacro.php*.

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