21 Feb 2025
07:11 PM
- last edited on
24 Feb 2025
11:05 AM
by
MaciejNeumann
Hi,
When trying to add a tag via the API with python, I'm receiving this error:
{"error":{"code":400,"message":"Constraints violated.","constraintViolations":[{"path":"tags","message":"must not be null","parameterLocation":"PAYLOAD_BODY","location":null}]}}
This is the code I'm using (note url_fstring = the request url with the entity id)
tag_body_data = {"context": "CONTEXTLESS","key": "Tag_to_be_added"}
tag_body_response = requests.post(url_fstring, headers={"Content-Type": "application/json",'Authorization': "Api-Token " + api_token}, data=json.dumps(tag_body_data), verify=False)
How do I make sense of that error response, or does anyone have a python code sample of assigning a simple tag to a entityID?
Thanks!
Solved! Go to Solution.
21 Feb 2025 08:52 PM
Your payload is not correct. It expects the tags structure which is missing in your payload. Please follow the API docs https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/custom-t... .
24 Feb 2025 04:23 PM
After changing the tag_body_data variable to below, it worked. Thanks!
tag_body_data = {
"tags": [
{
"key": "Tag_to_be_added"
},
]
}