[comment]: # ({c572a02a-c572a02a})
# host.update

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

[comment]: # ({7ee0d5db-7ee0d5db})
### Description

`object host.update(object/array hosts)`

This method allows to update existing hosts.

[comment]: # ({/7ee0d5db-7ee0d5db})

[comment]: # ({927c43fc-503bb6ac})
### Parameters

`(object/array)` Host properties to be updated.

The `hostid` property must be defined for each host, all other
properties are optional. Only the given properties will be updated, all
others will remain unchanged.

Additionally to the [standard host properties](object#host), the method
accepts the following parameters.

|Parameter|Type|Description|
|---------|----|-----------|
|groups|object/array|Host groups to replace the current host groups the host belongs to.<br><br>The host groups must have the `groupid` property defined.|
|interfaces|object/array|Host interfaces to replace the current host interfaces.|
|inventory|object|Host inventory properties.|
|macros|object/array|User macros to replace the current user macros.|
|templates|object/array|Templates to replace the currently linked templates. Templates that are not passed are only unlinked.<br><br>The templates must have the `templateid` property defined.|
|templates\_clear|object/array|Templates to unlink and clear from the host.<br><br>The templates must have the `templateid` property defined.|

::: notetip
As opposed to the Zabbix frontend, when `name` is the
same as `host`, updating `host` will not automatically update `name`.
Both properties need to be updated explicitly.
:::

[comment]: # ({/927c43fc-503bb6ac})

[comment]: # ({d166b99b-d166b99b})
### Return values

`(object)` Returns an object containing the IDs of the updated hosts
under the `hostids` property.

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

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

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

[comment]: # ({ce50c453-ce50c453})
#### Enabling a host

Enable host monitoring, i.e. set its status to 0.

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "status": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

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

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

[comment]: # ({bea1db7e-bea1db7e})
#### Unlinking templates

Unlink and clear two templates from host.

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "templates_clear": [
            {
                "templateid": "10124"
            },
            {
                "templateid": "10125"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

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

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

[comment]: # ({d5c60dd8-d5c60dd8})
#### Updating host macros

Replace all host macros with two new ones.

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "macros": [
            {
                "macro": "{$PASS}",
                "value": "password"
            },
            {
                "macro": "{$DISC}",
                "value": "sda"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

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

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

[comment]: # ({6b8e3616-6b8e3616})
#### Updating host inventory

Change inventory mode and add location

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "inventory_mode": 0,
        "inventory": {
            "location": "Latvia, Riga"
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10387"
        ]
    },
    "id": 2
}
```

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

[comment]: # ({0ffd02f4-0ffd02f4})
### See also

-   [host.massadd](massadd)
-   [host.massupdate](massupdate)
-   [host.massremove](massremove)
-   [Host group](/manual/api/reference/hostgroup/object#host_group)
-   [Template](/manual/api/reference/template/object#template)
-   [User
    macro](/manual/api/reference/usermacro/object#hosttemplate_level_macro)
-   [Host
    interface](/manual/api/reference/hostinterface/object#host_interface)
-   [Host inventory](object#host_inventory)

[comment]: # ({/0ffd02f4-0ffd02f4})

[comment]: # ({3b1b47a0-3b1b47a0})
### Source

CHost::update() in
*frontends/php/include/classes/api/services/CHost.php*.

[comment]: # ({/3b1b47a0-3b1b47a0})
