# API to pull all host group ID's

**URL:** <https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [February 18, 2022, 4:43pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197 "2022-02-18T16:43:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee\_rovner](https://avatars.discourse-cdn.com/v4/letter/l/c4cdca/32.png) [@lee\_rovner](https://community.dynatrace.com/u/lee_rovner)\
**Post date:** [February 18, 2022, 4:43pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/1 "2022-02-18T16:43:30Z")

</div>

I am trying to pull in ALL my hostgroup ID’s from the DT API.

It used to work using

https:// [xxxxxlive.dynatrace.com/api/v1/entity/infrastructure/hosts?tag=ds%3Aprod&showMonitoringCandidates=false&includeDetails=true](http://xxxxxlive.dynatrace.com/api/v1/entity/infrastructure/hosts?tag=ds%3Aprod&showMonitoringCandidates=false&includeDetails=true)

now, I am getting blank hostGroups

---

<div class="post-metadata">

**Author:** ![axel\_ayala](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@axel\_ayala](https://community.dynatrace.com/u/axel_ayala)\
**Post date:** [March 3, 2022, 9:13am UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/2 "2022-03-03T09:13:30Z")

</div>

You can try using the&nbsp; **Monitored Entities API,** &nbsp;using the entity type HOST\_GROUP should give you what you are looking for:

```auto
/api/v2/entities?entitySelector=type%28%22host_group%22%29

```

---

<div class="post-metadata">

**Author:** ![mherbert](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mherbert](https://community.dynatrace.com/u/mherbert)\
**Post date:** [June 20, 2023, 1:42pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/3 "2023-06-20T13:42:16Z")

</div>

Hi Axel,

There appears to be a bug in this API, when issuing a nextPageKey parameter is throws an exception

```javascript
{
  "error": {
    "code": 400,
    "message": "Constraints violated.",
    "constraintViolations": [
      {
        "path": "entitySelector",
        "message": "must not be used in combination with nextPageKey query parameter.",
        "parameterLocation": "QUERY",
        "location": null
      },
      {
        "path": "pageSize",
        "message": "must not be used in combination with nextPageKey query parameter.",
        "parameterLocation": "QUERY",
        "location": null
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mike\_S](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Mike\_S](https://community.dynatrace.com/u/Mike_S)\
**Post date:** [August 18, 2023, 5:58pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/4 "2023-08-18T17:58:47Z")

</div>

You must remove ALL parameters before using the&nbsp;nextPageKey or you will get the errors you show here.

---

<div class="post-metadata">

**Author:** ![funkymike7](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@funkymike7](https://community.dynatrace.com/u/funkymike7)\
**Post date:** [February 5, 2024, 9:43pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/5 "2024-02-05T21:43:39Z")

</div>

This is very useful information and I was able to get the list of host groups using the API.&nbsp; The only question I have is how do I associate these host\_groups to the hosts themselves?&nbsp; I don’t see a shared host Id/host group id, or at least know how to properly format the URL to pull both information together to allow me to view what host groups are associated to a given host.

---

<div class="post-metadata">

**Author:** ![axel\_ayala](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@axel\_ayala](https://community.dynatrace.com/u/axel_ayala)\
**Post date:** [February 5, 2024, 9:59pm UTC](https://community.dynatrace.com/t/api-to-pull-all-host-group-ids/34197/6 "2024-02-05T21:59:48Z")

</div>

I dont think the Host group monitored API information gives you that, unfortunately you would need a second call for hosts, and that info is part of the available properties:

```auto
/api/v2/entities?entitySelector=type("host")&fields=properties.hostgroupname

```
