Custom tags API - POST tags
Add custom tags to the specified monitored entities.
The request consumes and produces an application/json
payload.
POST | ManagedDynatrace for Government | https://{your-domain}/e/{your-environment-id}/api/v2/tags |
SaaS | https://{your-environment-id}.live.dynatrace.com/api/v2/tags | |
Environment and Cluster ActiveGate (default port 9999) | https://{your-activegate-domain}:9999/e/{your-environment-id}/api/v2/tags |
Authentication
To execute this request, you need an access token with entities.write
scope.
To learn how to obtain and use it, see Tokens and authentication.
Parameters
Parameter | Type | Description | In | Required |
---|---|---|---|---|
entitySelector | string | Specifies the entities where you want to update tags. You must set one of these criteria:
You can add one or more of the following criteria. Values are case-sensitive and the
For more information, see Entity selector in Dynatrace Documentation. To set several criteria, separate them with a comma ( The maximum string length is 2,000 characters. | query | required |
from | string | The start of the requested timeframe. You can use one of the following formats:
If not set, the relative timeframe of 24 hours is used ( | query | optional |
to | string | The end of the requested timeframe. You can use one of the following formats:
If not set, the current timestamp is used. | query | optional |
body | AddEntityTags | The JSON body of the request. Contains tags to be added to the matching entities. | body | optional |
Request body objects
The AddEntityTags
object
A list of tags to be added to monitored entities.
Element | Type | Description | Required |
---|---|---|---|
tags | AddEntityTag[] | A list of tags to be added to monitored entities. | required |
The AddEntityTag
object
The custom tag to be added to monitored entities.
Element | Type | Description | Required |
---|---|---|---|
key | string | The key of the custom tag to be added to monitored entities. | required |
value | string | The value of the custom tag to be added to monitored entities. May be null | optional |
Request body JSON model
This is a model of the request body, showing the possible elements. It has to be adjusted for usage in an actual request.
1{2 "tags": [3 {4 "key": "mainApp"5 },6 {7 "key": "bookings",8 "value": "42"9 }10 ]11}
Response
Response codes
Code | Type | Description |
---|---|---|
200 | AddedEntityTags | Success |
Response body objects
The AddedEntityTags
object
A list of custom tags added to monitored entities.
Element | Type | Description |
---|---|---|
appliedTags | METag[] | A list of added custom tags. |
matchedEntitiesCount | integer | The number of monitored entities where the tags have been added. |
The METag
object
The tag of a monitored entity.
Element | Type | Description |
---|---|---|
context | string | The origin of the tag, such as AWS or Cloud Foundry. Custom tags use the |
key | string | The key of the tag. |
stringRepresentation | string | The string representation of the tag. |
value | string | The value of the tag. |
Response body JSON model
1{2 "appliedTags": [3 {4 "context": "CONTEXTLESS",5 "key": "mainApp",6 "stringRepresentation": "mainApp"7 },8 {9 "context": "CONTEXTLESS",10 "key": "booking",11 "stringRepresentation": "booking"12 }13 ],14 "matchedEntitiesCount": 215}
Example
In this example, the request adds the REST-test and RESTexample custom tags to hosts that already have the easyTravel tag. To achieve that, the entitySelector query parameter is set to type("HOST"),tag("easyTravel")
.
The API token is passed in the Authorization header.
Curl
1curl -L -X POST 'https://mySampleEnv.live.dynatrace.com/api/v2/tags?entitySelector=type(%22HOST%22),tag(%22easyTravel%22)' \2-H 'Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890' \3-H 'Content-Type: application/json' \4--data-raw '{5 "tags": [6 {7 "key": "REST-test"8 },9 {10 "key": "RESTexample"11 }12 ]13}'
Request URL
1https://mySampleEnv.live.dynatrace.com/api/v2/tags?entitySelector=type(%22HOST%22),tag(%22easyTravel%22)
Request body
1{2 "tags": [3 {4 "key": "REST-test"5 },6 {7 "key": "RESTexample"8 }9 ]10}
Response body
1{2 "matchedEntitiesCount": 3,3 "appliedTags": [4 {5 "context": "CONTEXTLESS",6 "key": "REST-test",7 "stringRepresentation": "REST-test"8 },9 {10 "context": "CONTEXTLESS",11 "key": "RESTexample",12 "stringRepresentation": "RESTexample"13 }14 ]15}
Response code
200