# V2 API - Easy way to count the number of entities in a tag?

**URL:** <https://community.dynatrace.com/t/v2-api-easy-way-to-count-the-number-of-entities-in-a-tag/35528>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [June 17, 2022, 4:08pm UTC](https://community.dynatrace.com/t/v2-api-easy-way-to-count-the-number-of-entities-in-a-tag/35528 "2022-06-17T16:08:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![louis\_gallo](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@louis\_gallo](https://community.dynatrace.com/u/louis_gallo)\
**Post date:** [June 17, 2022, 4:08pm UTC](https://community.dynatrace.com/t/v2-api-easy-way-to-count-the-number-of-entities-in-a-tag/35528/1 "2022-06-17T16:08:51Z")

</div>

I am fairly accomplished in pulling back time series data in the V2 API, but my question is this:

A user could in fact specify a tag name that has thousands of entities tied to it. For example - “server:servername” versus just “server”.

Is there an easy was to pull back just the number of entities count for a particular tag?

I can use this as a pre-check safeguard to ensure my API will not try to pull back data for thousands of servers.

Any advice is appreciated.

Thanks,

Lou

---

<div class="post-metadata">

**Author:** ![mgome](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mgome](https://community.dynatrace.com/u/mgome)\
**Post date:** [June 17, 2022, 5:29pm UTC](https://community.dynatrace.com/t/v2-api-easy-way-to-count-the-number-of-entities-in-a-tag/35528/2 "2022-06-17T17:29:18Z")

</div>

You can use an entity selector on the&nbsp;/api/v2/entities endpoint of the Monitored Entities API. &nbsp;For example if you’re looking for hosts with a specific tag:

type(HOST),tag(“[context]key”)

Or, if you’re looking for hosts with a specific tag value:

type(HOST),tag(“[context]key:value”)

context is for specific types of tags like [Environment] or [Azure] and isn’t needed if your tag does not have a context.

The JSON returned will have a “totalCount” which is the number of entities with a tag or tag:value. &nbsp;You can set your pagesize to 1 if all you’re interested in is the total number of entities and not the list of entities.
