# Get host ID using API

**URL:** <https://community.dynatrace.com/t/get-host-id-using-api/34753>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [April 7, 2022, 9:10am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753 "2022-04-07T09:10:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gary1024](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gary1024/32/30648_2.png) [@gary1024](https://community.dynatrace.com/u/gary1024)\
**Post date:** [April 7, 2022, 9:10am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/1 "2022-04-07T09:10:53Z")

</div>

Hi

I need help to find a way to get hostid using an API. I know hostid can be found on the URL like this:

[https://my-domain/e/my-environment/#newhosts/hostdetails;id=HOST-B0363C0D000000000;gtf=-72h%20to%20now;gf=all](https://my-domain/e/my-environment/#newhosts/hostdetails;id=HOST-B0363C0D000000000;gtf=-72h%20to%20now;gf=all)

However, I need to have a way to query from the OneAgent host itself so that I can use it to trigger enable/disable API from there.

Gary

---

<div class="post-metadata">

**Author:** ![pahofmann](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pahofmann/32/17076_2.png) [@pahofmann](https://community.dynatrace.com/u/pahofmann)\
**Post date:** [April 7, 2022, 9:23am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/2 "2022-04-07T09:23:19Z")

</div>

You can use the&nbsp;[Monitored Entities Endpoint in the Environment v2 API](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/get-entities-list)&nbsp;to get the Host IDs

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [April 7, 2022, 12:07pm UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/3 "2022-04-07T12:07:12Z")

</div>

The [Hosts API](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/topology-and-smartscape/hosts-api/get-all) will also do the job.

---

<div class="post-metadata">

**Author:** ![gary1024](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gary1024/32/30648_2.png) [@gary1024](https://community.dynatrace.com/u/gary1024)\
**Post date:** [April 8, 2022, 2:08am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/4 "2022-04-08T02:08:24Z")

</div>

Thanks for the reply. Sorry for not being specific.

A list of HOSTID and other parameters will not help.

My use case is that I need to configure my AWS instance to query the HOSTID of the instance in Dynatrace (by its Instance-ID or detected name) and store it in a variable to be use in the OneAgent enable/disable API.

---

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [April 8, 2022, 2:30am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/5 "2022-04-08T02:30:49Z")

</div>

Hi&nbsp;[@gary1024](https://community.dynatrace.com/user/13094)

You can do this using OneAgent on a host API,

- First you need to use, **/oneagents** API to get the host id (Environment API)
- Second, you need to use&nbsp; **/hosts/{id}/monitoring** API to update the monitoringEnabled parameter. (Configuration API)
  - 

```auto
<span>{</span>
  <span>"monitoringEnabled"</span><span>:</span> <span>true</span><span>,</span>
  <span>"monitoringMode"</span><span>:</span> <span>"FULL_STACK"</span>
<span>}</span>

```

---

<div class="post-metadata">

**Author:** ![Fin\_Ubels](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/fin_ubels/32/18008_2.png) [@Fin\_Ubels](https://community.dynatrace.com/u/Fin_Ubels)\
**Post date:** [April 8, 2022, 4:17am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/6 "2022-04-08T04:17:43Z")

</div>

Hey NKIANKEONG,  
Instead of the APIs you could also use the oneagentctl tool to get the HostID of specific hosts. It’s bundled with OneAgent when you install it so it will be on every host. So you could set up some system to remotely trigger it to run and then get the response from it.

> **[OneAgent configuration via command-line interface](https://docs.dynatrace.com/docs/ingest-from/dynatrace-oneagent/oneagent-configuration-via-command-line-interface)**
>
> Learn how to perform some OneAgent configuration tasks without the need to reinstall OneAgent.

---

<div class="post-metadata">

**Author:** ![gary1024](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gary1024/32/30648_2.png) [@gary1024](https://community.dynatrace.com/u/gary1024)\
**Post date:** [April 8, 2022, 4:46am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/7 "2022-04-08T04:46:04Z")

</div>

Thanks to everyone that contribute to this. Problem solved!

This is the solution:

[environment-api/entity-v2/get-entities-list](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/get-entities-list?_ga=2.213797524.1882343407.1649305572-1936452222.1646239584&_gac=1.247131824.1649056799.EAIaIQobChMItvL9--T59gIVZJNmAh0CfQGfEAAYASACEgKfRfD_BwE)

And this simple API will get me the HOSTID I need:

https://{my-domain}/e/{my-environment}/api/v2/entities?Api-Token={my-token}&entitySelector=type(%22HOST%22),entityName(%22{my-detected-name}%22)

The result:

totalCount: 1  
pageSize: 50  
entities:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entityId: “HOST-xxxxxxxxxxxxxxx”  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; displayName: “MicroServices - ip-xx-xxx-xx-xx.aws.men.maxis.com.my”

| |
| --- |

---

<div class="post-metadata">

**Author:** ![vzd68890](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vzd68890](https://community.dynatrace.com/u/vzd68890)\
**Post date:** [March 9, 2023, 1:02am UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/8 "2023-03-09T01:02:41Z")

</div>

It is so complicated to find so simple information . It is not user friendly .

---

<div class="post-metadata">

**Author:** ![v\_mayordomo](https://avatars.discourse-cdn.com/v4/letter/v/ad7895/32.png) [@v\_mayordomo](https://community.dynatrace.com/u/v_mayordomo)\
**Post date:** [March 20, 2025, 12:07pm UTC](https://community.dynatrace.com/t/get-host-id-using-api/34753/9 "2025-03-20T12:07:55Z")

</div>

Hi. I see that this thread is already closed, but in case someone is useful, it is a good idea to filter only for those hosts that are being monitored (we discard all ESXi discovered in vCenter) and by the way, not return only 50 results and can specify the number we want. This is the call to return the ID of each server, (necessary to use the API) only if it is in “FULL-STACK” and returning 100 results.

url = ‘https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type%28%22HOST%22%29,monitoringMode(%22FULL\_STACK%22)&pageSize=100’

In our case we use it to enable or disable by API the monitoring of HOSTs through a python script.  
Greetings.
