[comment]: # ({f8d4c2e5-f8d4c2e5})
# hostgroup.get

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

[comment]: # ({20294517-08ff22f2})
### Description

`integer/array hostgroup.get(object parameters)`

The method allows to retrieve host groups according to the given parameters.

::: noteclassic
This method is available to users of any type.
Permissions to call the method can be revoked in user role settings.
See [User roles](/manual/web_interface/frontend_sections/users/user_roles) for more information.
:::

[comment]: # ({/20294517-08ff22f2})

[comment]: # ({5291ff51-7f042696})
### Parameters

`(object)` Parameters defining the desired output.

The method supports the following parameters.

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Description|
|--|--|------|
|graphids|ID/array|Return only host groups that contain hosts with the given graphs.|
|groupids|ID/array|Return only host groups with the given host group IDs.|
|hostids|ID/array|Return only host groups that contain the given hosts.|
|maintenanceids|ID/array|Return only host groups that are affected by the given maintenances.|
|triggerids|ID/array|Return only host groups that contain hosts with the given triggers.|
|with\_graphs|boolean|Return only host groups that contain hosts with graphs.|
|with\_graph\_prototypes|boolean|Return only host groups that contain hosts with graph prototypes.|
|with\_hosts|boolean|Return only host groups that contain hosts.|
|with\_httptests|boolean|Return only host groups that contain hosts with web checks.<br><br>Overrides the `with_monitored_httptests` parameter.|
|with\_items|boolean|Return only host groups that contain hosts with items.<br><br>Overrides the `with_monitored_items` and `with_simple_graph_items` parameters.|
|with\_item\_prototypes|boolean|Return only host groups that contain hosts with item prototypes.<br><br>Overrides the `with_simple_graph_item_prototypes` parameter.|
|with\_simple\_graph\_item\_prototypes|boolean|Return only host groups that contain hosts with item prototypes, which are enabled for creation and have numeric type of information.|
|with\_monitored\_httptests|boolean|Return only host groups that contain hosts with enabled web checks.|
|with\_monitored\_hosts|boolean|Return only host groups that contain monitored hosts.|
|with\_monitored\_items|boolean|Return only host groups that contain hosts with enabled items.<br><br>Overrides the `with_simple_graph_items` parameter.|
|with\_monitored\_triggers|boolean|Return only host groups that contain hosts with enabled triggers. All of the items used in the trigger must also be enabled.|
|with\_simple\_graph\_items|boolean|Return only host groups that contain hosts with numeric items.|
|with\_triggers|boolean|Return only host groups that contain hosts with triggers.<br><br>Overrides the `with_monitored_triggers` parameter.|
|selectDiscoveryRules|query|Return a [`discoveryRules`](/manual/api/reference/discoveryrule/object) property with the LLD rules that discovered the host group.|
|selectDiscoveryData|query|Return a `discoveryData` property with the host group discovery objects.<br><br>Each host group discovery object is a host group prototype linked to the discovered host group and has the following properties:<br>`parent_group_prototypeid` - `(ID)` ID of the host group prototype from which the host group was discovered;<br>`name` - `(string)` name of the host group prototype;<br>`ts_delete` - `(timestamp)` time when the host group that is no longer discovered will be deleted;<br>`status` - `(int)` host group discovery status:<br>0 - *(default)* host group is discovered,<br>1 - host group is not discovered anymore.|
|selectHostPrototypes|query|Return a [`hostPrototypes`](/manual/api/reference/hostprototypes/object) property with host prototypes that discovered this host group.|
|selectHosts|query|Return a [`hosts`](/manual/api/reference/host/object) property with the hosts that belong to the host group.<br><br>Supports `count`.|
|limitSelects|integer|Limits the number of records returned by subselects.<br><br>Applies to the following subselects:<br>`selectHosts` - results will be sorted by `host`.|
|sortfield|string/array|Sort the result by the given properties.<br><br>Possible values: `groupid`, `name`.|
|countOutput|boolean|These parameters are described in the [reference commentary](/manual/api/reference_commentary#common-get-method-parameters).|
|editable|boolean|^|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|
|selectGroupDiscoveries|query|Return a `groupDiscoveries` property with the host group discovery objects.<br><br>Each host group discovery object is a host group prototype linked to the discovered host group.<br><br>This query is **deprecated**, please use `selectDiscoveryData` instead.|

[comment]: # ({/5291ff51-7f042696})

[comment]: # ({07ca11ca-7223bab1})
### Return values

`(integer/array)` Returns either:

-   an array of objects
-   the count of retrieved objects, if the `countOutput` parameter has been used

[comment]: # ({/07ca11ca-7223bab1})

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

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

[comment]: # ({6271b06c-8ed2756a})
#### Retrieving data by name

Retrieve all data about two host groups named "Zabbix servers" and "Linux servers".

[Request](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": "extend",
        "filter": {
            "name": [
                "Zabbix servers",
                "Linux servers"
            ]
        }
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "groupid": "2",
            "name": "Linux servers",
            "flags": "0",
            "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
        },
        {
            "groupid": "4",
            "name": "Zabbix servers",
            "flags": "0",
            "uuid": "6f6799aa69e844b4b3918f779f2abf08"
        }
    ],
    "id": 1
}
```

[comment]: # ({/6271b06c-8ed2756a})

[comment]: # ({6a994b89-e5f0abe1})
### See also

-   [Host](/manual/api/reference/host/object#host)

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

[comment]: # ({1e72ea39-1e72ea39})
### Source

CHostGroup::get() in *ui/include/classes/api/services/CHostGroup.php*.

[comment]: # ({/1e72ea39-1e72ea39})
