[comment]: # ({cc00d3db-cc00d3db})
# itemprototype.update

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

[comment]: # ({63442cbb-63442cbb})
### 描述

`object itemprototype.update(object/array itemPrototypes)`

此方法允许update现有的监控项原型.

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

:::

[comment]: # ({/63442cbb-63442cbb})

[comment]: # ({3b327914-16fcb884})
### 参数

`(object/array)` 监控项 原型属性待更新。

每个监控项原型必须定义`itemid`属性，其他
属性均为可选。仅传递的属性会被更新，所有
其他属性将保持不变。

除[监控项原型](object#监控项原型)外，该方法还接受以下
参数。

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| preprocessing | array | 用于替换当前预处理选项的监控项原型[监控项-原型预处理](/manual/api/reference/itemprototype/object#监控项-原型预处理)选项。 |
| tags | array | 监控项原型[监控项-原型标签](/manual/api/reference/itemprototype/object#监控项-原型标签)。 |

[comment]: # ({/3b327914-16fcb884})

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

`(object)` 返回一个包含更新后的object ID的监控项原型数组
存储在`itemids`属性下

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

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

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

[comment]: # ({c90dddc6-48cea947})
#### 修改 监控项 原型的接口

更改将被发现的监控项所使用的主机接口。

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "itemprototype.update",
    "params": {
        "itemid": "27428",
        "interfaceid": "132"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```
响应:

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

[comment]: # ({/c90dddc6-48cea947})

[comment]: # ({37e481d4-e1d8fc73})
#### 更新依赖的 监控项 原型

使用新的主监控项原型ID更新依赖监控项原型。仅
允许在同一主机（模板/发现规则）上存在依赖关系
因此主节点和从属节点的监控项应具有相同的hostid和ruleid。

请求

```json
{
    "jsonrpc": "2.0",
    "method": "itemprototype.update",
    "params": {
        "master_itemid": "25570",
        "itemid": "189030"
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应

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

[comment]: # ({/37e481d4-e1d8fc73})

[comment]: # ({988b9bcb-d7fe7206})
#### 更新 HTTP agent 监控项 原型

修改query字段并移除所有自定义头部

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "itemprototype.update",
    "params": {
        "itemid":"28305",
        "query_fields": [
            {
                "random": "qwertyuiopasdfghjklzxcvbnm"
            }
        ],
        "headers": []
    }
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应:

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

[comment]: # ({/988b9bcb-d7fe7206})

[comment]: # ({e7525f97-e5fc44e0})
#### 更新 监控项 预处理选项

使用监控项预处理规则“Custom”更新监控项原型
乘数”。

请求

```json
{
    "jsonrpc": "2.0",
    "method": "itemprototype.update",
    "params": {
        "itemid": "44211",
        "preprocessing": [
            {
                "type": 1,
                "params": "4",
                "error_handler": 2,
                "error_handler_params": "5"
            }
        ]
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应

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

[comment]: # ({/e7525f97-e5fc44e0})

[comment]: # ({3908deff-15ba4525})
#### 更新脚本 监控项 原型

使用不同的脚本更新脚本监控项原型，并移除先前脚本使用的不必要参数。

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "itemprototype.update",
    "params": {
        "itemid": "23865",
        "parameters": [],
        "script": "Zabbix.Log(3, 'Log test');\nreturn 1;"
    },
    "auth": "700ca65537074ec963db7efabda78259",
    "id": 1
}
```
响应:

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

[comment]: # ({/3908deff-15ba4525})

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

CItemPrototype::update() 位于
*ui/include/classes/api/services/CItemPrototype.php* 文件中。

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