Custom tags API - GET tags
Lists all custom tags assigned to the specified monitored entities. Automatically applied tags and imported tags are not included.
The request produces an application/json
payload.
GET | SaaS | https://{your-environment-id}.live.dynatrace.com/api/v2/tags |
Environment ActiveGateCluster ActiveGate | https://{your-activegate-domain}:9999/e/{your-environment-id}/api/v2/tags |
Authentication
To execute this request, you need an access token with entities.read
scope.
To learn how to obtain and use it, see Tokens and authentication.
Parameters
Specifies the entities where you want to read tags.
You must set one of these criteria:
- Entity type:
type("TYPE")
- Dynatrace entity ID:
entityId("id")
. You can specify several IDs, separated by a comma (entityId("id-1","id-2")
). All requested entities must be of the same type.
You can add one or more of the following criteria. Values are case-sensitive and the EQUALS
operator is used unless otherwise specified.
- Tag:
tag("value")
. Tags in[context]key:value
,key:value
, andvalue
formats are detected and parsed automatically. Any colons (:
) that are part of the key or value must be escaped with a backslash(\
). Otherwise, it will be interpreted as the separator between the key and the value. All tag values are case-sensitive. - Management zone ID:
mzId(123)
- Management zone name:
mzName("value")
- Entity name:
entityName.equals
: performs a non-casesensitiveEQUALS
query.entityName.startsWith
: changes the operator toBEGINS WITH
.entityName.in
: enables you to provide multiple values. TheEQUALS
operator applies.caseSensitive(entityName.equals("value"))
: takes any entity name criterion as an argument and makes the value case-sensitive.
- Health state (HEALTHY,UNHEALTHY):
healthState("HEALTHY")
- First seen timestamp:
firstSeenTms.<operator>(now-3h)
. Use any timestamp format from the from/to parameters. The following operators are available:lte
: earlier than or at the specified timelt
: earlier than the specified timegte
: later than or at the specified timegt
: later than the specified time
- Entity attribute:
<attribute>("value1","value2")
and<attribute>.exists()
. To fetch the list of available attributes, execute the GET entity type request and check the properties field of the response. - Relationships:
fromRelationships.<relationshipName>()
andtoRelationships.<relationshipName>()
. This criterion takes an entity selector as an attribute. To fetch the list of available relationships, execute the GET entity type request and check the fromRelationships and toRelationships fields. - Negation:
not(<criterion>)
. Inverts any criterion except for type.
For more information, see Entity selector in Dynatrace Documentation.
To set several criteria, separate them with a comma (,
). For example, type("HOST"),healthState("HEALTHY")
. Only results matching all criteria are included in the response.
The maximum string length is 2,000 characters.
The start of the requested timeframe.
You can use one of the following formats:
- Timestamp in UTC milliseconds.
- Human-readable format of
2021-01-25T05:57:01.123+01:00
. If no time zone is specified, UTC is used. You can use a space character instead of theT
. Seconds and fractions of a second are optional. - Relative timeframe, back from now. The format is
now-NU/A
, whereN
is the amount of time,U
is the unit of time, andA
is an alignment. The alignment rounds all the smaller values to the nearest zero in the past. For example,now-1y/w
is one year back, aligned by a week. You can also specify relative timeframe without an alignment:now-NU
. Supported time units for the relative timeframe are:m
: minutesh
: hoursd
: daysw
: weeksM
: monthsy
: years
If not set, the relative timeframe of 24 hours is used (now-24h
).
The end of the requested timeframe.
You can use one of the following formats:
- Timestamp in UTC milliseconds.
- Human-readable format of
2021-01-25T05:57:01.123+01:00
. If no time zone is specified, UTC is used. You can use a space character instead of theT
. Seconds and fractions of a second are optional. - Relative timeframe, back from now. The format is
now-NU/A
, whereN
is the amount of time,U
is the unit of time, andA
is an alignment. The alignment rounds all the smaller values to the nearest zero in the past. For example,now-1y/w
is one year back, aligned by a week. You can also specify relative timeframe without an alignment:now-NU
. Supported time units for the relative timeframe are:m
: minutesh
: hoursd
: daysw
: weeksM
: monthsy
: years
If not set, the current timestamp is used.
Response
Response codes
Response body objects
The CustomEntityTags
object
A list of custom tags.
The total number of tags in the response.
The METag
object
The tag of a monitored entity.
The origin of the tag, such as AWS or Cloud Foundry.
Custom tags use the CONTEXTLESS
value.
The key of the tag.
The string representation of the tag.
The value of the tag.
Response body JSON model
{"tags": [{"context": "CONTEXTLESS","key": "mainApp","stringRepresentation": "mainApp"},{"context": "CONTEXTLESS","key": "bookings","stringRepresentation": "bookings"}],"totalCount": 2}
Example
In this example, the request lists custom tags that are applied to services that belong to the management zones with the ID of 229130632296508575249. To achieve that, the entitySelector query parameter is set to type("SERVICE"),mzId("9130632296508575249")
.
The API token is passed in the Authorization header.
Because the full result is rather lengthy, it is truncated to three entries.
Curl
curl -L -X GET 'https://mySampleEnv.live.dynatrace.com/api/v2/tags?entitySelector=type(%22SERVICE%22),mzId(%229130632296508575249%22)' \-H 'Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890'
Request URL
https://mySampleEnv.live.dynatrace.com/api/v2/tags?entitySelector=type(%22SERVICE%22),mzId(%229130632296508575249%22)
Response body
{"totalCount": 31,"tags": [{"context": "CONTEXTLESS","key": "Billing","stringRepresentation": "Billing"},{"context": "CONTEXTLESS","key": "Booking","stringRepresentation": "Booking"},{"context": "CONTEXTLESS","key": "easytravel","value": "backend","stringRepresentation": "easytravel:backend"}]}
Response code
200