[comment]: # ({959fe29c-959fe29c})
# item.create

[comment]: # ({/959fe29c-959fe29c})

[comment]: # ({40d3ae0b-e3078f54})
### 説明

`object item.create(object/array items)`

このメソッドは新しいアイテムを作成するためのものです。

::: noteclassic
WebアイテムはZabbix API経由では作成できません。
:::

::: noteclassic
このメソッドは*管理者*および*Zabbix管理者*ユーザータイプでのみ利用可能です。
このメソッドを呼び出す権限はユーザーロールの設定で取り消すことができます。
詳細は[ユーザーロール](/manual/web_interface/frontend_sections/users/user_roles)を参照してください。
:::

[comment]: # ({/40d3ae0b-e3078f54})

[comment]: # ({01affbf6-777e8bec})
### パラメータ

`(object/array)` 作成するアイテム。

[標準のアイテムプロパティ](object#host)に加えて、このメソッドは以下のパラメータを受け付けます。

|パラメータ|[Type](/manual/api/reference_commentary#data-types)|説明|
|--|--|------|
|preprocessing|array|[アイテムの前処理](/manual/api/reference/item/object#item-preprocessing)オプション。|
|tags|array|[アイテムタグ](/manual/api/reference/item/object#item-tag)。|

[comment]: # ({/01affbf6-777e8bec})

[comment]: # ({6346b142-632959fe})
### 戻り値

`(object)` 作成されたアイテムのIDを `itemids` プロパティに含むオブジェクトを返します。
返されるIDの順序は、渡されたアイテムの順序と一致します。

[comment]: # ({/6346b142-632959fe})

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

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

[comment]: # ({560d3235-6ffb1f45})
#### アイテムの作成

ID "30074" のホストで空きディスク容量を監視するために、2つのアイテムタグを持つ数値型Zabbixエージェントアイテムを作成します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Free disk space on /home/joe/",
        "key_": "vfs.fs.size[/home/joe/,free]",
        "hostid": "30074",
        "type": 0,
        "value_type": 3,
        "interfaceid": "30084",
        "tags": [
            {
                "tag": "component",
                "value": "storage"
            },
            {
                "tag": "equipment",
                "value": "workstation"
            }
        ],
        "delay": "30s"
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/560d3235-6ffb1f45})

[comment]: # ({91af8fa5-0f29886e})
#### ホストインベントリアイテムの作成

ホストの「OS」インベントリフィールドを埋めるために、Zabbixエージェントアイテムを作成します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "uname",
        "key_": "system.uname",
        "hostid": "30021",
        "type": 0,
        "interfaceid": "30007",
        "value_type": 1,
        "delay": "10s",
        "inventory_link": 5
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/91af8fa5-0f29886e})

[comment]: # ({cbc056d5-f45b1a9a})
#### 前処理付きアイテムの作成

カスタム乗数を使用してアイテムを作成します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Device uptime",
        "key_": "sysUpTime",
        "hostid": "10084",
        "type": 20,
        "snmp_oid": "SNMPv2-MIB::sysUpTime.0",
        "value_type": 1,
        "delay": "60s",
        "interfaceid": "83",
        "preprocessing": [
            {
                "type": 1,
                "params": "0.01",
                "error_handler": 1,
                "error_handler_params": ""
            }
        ]
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/cbc056d5-f45b1a9a})

[comment]: # ({fbd473da-6a32a64f})
#### 従属アイテムの作成

ID 24759のマスターアイテムに対して従属アイテムを作成します。
同じホストでのみ依存関係が許可されているため、マスターアイテムと従属アイテムは同じhostidである必要があります。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
      "hostid": "30074",
      "name": "Dependent test item",
      "key_": "dependent.item",
      "type": 18,
      "master_itemid": "24759",
      "value_type": 2
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/fbd473da-6a32a64f})

[comment]: # ({98de8418-70eb9eae})
#### HTTPエージェントアイテムの作成

JSONレスポンスの前処理を行うPOSTリクエストメソッドアイテムを作成します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "url":"http://127.0.0.1/http.php",
        "query_fields": [
            {
                "name": "mode",
                "value": "json"
            },
            {
                "name": "min",
                "value": "10"
            },
            {
                "name": "max",
                "value": "100"
            }
        ],
        "interfaceid": "1",
        "type": 19,
        "hostid": "10254",
        "delay": "5s",
        "key_": "json",
        "name": "HTTP agent example JSON",
        "value_type": 0,
        "output_format": 1,
        "preprocessing": [
            {
                "type": 12,
                "params": "$.random",
                "error_handler": 0,
                "error_handler_params": ""
            }
        ]
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/98de8418-70eb9eae})

[comment]: # ({568de3f0-313c9999})
#### スクリプトアイテムの作成

スクリプトアイテムを使用してシンプルなデータ収集を作成します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Script example",
        "key_": "custom.script.item",
        "hostid": "12345",
        "type": 21,
        "value_type": 4,
        "params": "var request = new HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
        "parameters": [
            {
                "name": "host",
                "value": "{HOST.CONN}"
            }
        ],
        "timeout": "6s",
        "delay": "30s"
    },
    "id": 1
}
```

レスポンス:

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

[comment]: # ({/568de3f0-313c9999})

[comment]: # ({ecb97b1d-ecb97b1d})
### ソース

CItem::create() in *ui/include/classes/api/services/CItem.php*.

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