cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error 400 via API post with python to add tag to entity. "Constraints violated."

tree_branch
Newcomer_

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!

2 REPLIES 2

Julius_Loman
DynaMight Legend
DynaMight Legend

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... .

Certified Dynatrace Master | Alanata a.s., Slovakia, Dynatrace Master Partner

tree_branch
Newcomer_

After changing the tag_body_data variable to below, it worked.  Thanks!

 

tag_body_data = {
    "tags": [
       {
          "key": "Tag_to_be_added"
       },

    ]
}

Featured Posts