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

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

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

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

Šī metode ļauj izveidot jaunus vienumus.

::: noteclassic
Tīmekļa vienumus nevar izveidot, izmantojot Zabbix API.
:::

::: noteclassic
Šī metode ir pieejama tikai *Admin* un *Super admin* lietotāju tipiem.
Atļaujas izsaukt šo metodi var atsaukt lietotāju lomu iestatījumos.
Plašāku informāciju skatiet sadaļā [Lietotāju lomas](/manual/web_interface/frontend_sections/users/user_roles).
:::

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

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

`(object/array)` Vienumi, ko izveidot.

Papildus [standarta vienuma īpašībām](object#host) metode pieņem šādus parametrus.

|Parametrs|[Tips](/manual/api/reference_commentary#data-types)|Apraksts|
|--|--|------|
|preprocessing|array|[Vienuma priekšapstrādes](/manual/api/reference/item/object#item-preprocessing) opcijas.|
|tags|array|[Vienuma birkas](/manual/api/reference/item/object#item-tag).|

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

[comment]: # ({6346b142-632959fe})
### Atgrieztās vērtības

`(object)` Atgriež objektu, kas satur izveidoto vienumu ID īpašībā `itemids`.
Atgriezto ID secība atbilst nodoto vienumu secībai.

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

[comment]: # ({b41637d2-b41637d2})
### Piemēri

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

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

Izveidojiet skaitlisku Zabbix aģenta vienumu ar 2 vienuma tagiem, lai uzraudzītu brīvo diska vietu hostā ar ID "30074".

[Pieprasījums](/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
}
```

Atbilde:

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

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

[comment]: # ({91af8fa5-0f29886e})
#### Hosts inventarizācijas vienuma izveide

Izveidojiet Zabbix aģents vienumu, lai aizpildītu hosta inventarizācijas lauku "OS".

[Pieprasījums](/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
}
```

Atbilde:

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

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

[comment]: # ({cbc056d5-f45b1a9a})
#### Vienuma izveide ar priekšapstrādi

Izveidojiet vienumu, izmantojot pielāgotu reizinātāju.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Ierīces darbības laiks",
        "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
}
```

Atbilde:

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

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

[comment]: # ({fbd473da-6a32a64f})
#### Atkarīgā vienuma izveide

Izveidojiet atkarīgo vienumu galvenajam vienumam ar ID 24759.
Ir atļautas tikai atkarības uz tā paša hosta, tādēļ galvenajam un atkarīgajam vienumam jābūt ar vienādu hostid.

[Pieprasījums](/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
}
```

Atbilde:

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

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

[comment]: # ({98de8418-70eb9eae})
#### Izveidot HTTP aģenta vienumu

Izveidojiet POST pieprasījuma metodes vienumu ar JSON atbildes priekšapstrādi.

[Pieprasījums](/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
}
```

Atbilde:

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

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

[comment]: # ({568de3f0-313c9999})
#### Izveidot skripta vienumu

Izveidojiet vienkāršu datu vākšanu, izmantojot skripta vienumu.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Skripta piemērs",
        "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
}
```

Atbilde:

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

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

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

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

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