<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error 400 via API post with python to add tag to entity.  &amp;quot;Constraints violated.&amp;quot; in Open Q&amp;A</title>
    <link>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270734#M35782</link>
    <description>&lt;P&gt;Your payload is not correct. It expects the tags structure which is missing in your payload. Please follow the API docs&amp;nbsp;&lt;A href="https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/custom-tags/post-tags" target="_blank"&gt;https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/custom-tags/post-tags&lt;/A&gt; .&lt;/P&gt;</description>
    <pubDate>Fri, 21 Feb 2025 20:52:04 GMT</pubDate>
    <dc:creator>Julius_Loman</dc:creator>
    <dc:date>2025-02-21T20:52:04Z</dc:date>
    <item>
      <title>Error 400 via API post with python to add tag to entity.  "Constraints violated."</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270730#M35781</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When trying to add a tag via the API with python, I'm receiving this error:&lt;/P&gt;
&lt;P&gt;{"error":{"code":400,"message":"Constraints violated.","constraintViolations":[{"path":"tags","message":"must not be null","parameterLocation":"PAYLOAD_BODY","location":null}]}}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I'm using (note url_fstring = the request url with the entity id)&lt;/P&gt;
&lt;P&gt;tag_body_data = {"context": "CONTEXTLESS","key": "Tag_to_be_added"}&lt;BR /&gt;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)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 11:05:07 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270730#M35781</guid>
      <dc:creator>tree_branch</dc:creator>
      <dc:date>2025-02-24T11:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error 400 via API post with python to add tag to entity.  "Constraints violated."</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270734#M35782</link>
      <description>&lt;P&gt;Your payload is not correct. It expects the tags structure which is missing in your payload. Please follow the API docs&amp;nbsp;&lt;A href="https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/custom-tags/post-tags" target="_blank"&gt;https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/custom-tags/post-tags&lt;/A&gt; .&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 20:52:04 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270734#M35782</guid>
      <dc:creator>Julius_Loman</dc:creator>
      <dc:date>2025-02-21T20:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error 400 via API post with python to add tag to entity.  "Constraints violated."</title>
      <link>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270848#M35799</link>
      <description>&lt;P&gt;After changing the tag_body_data variable to below, it worked.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tag_body_data = {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "tags": [&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; "key": "Tag_to_be_added"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; },&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ]&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 16:23:16 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Open-Q-A/Error-400-via-API-post-with-python-to-add-tag-to-entity-quot/m-p/270848#M35799</guid>
      <dc:creator>tree_branch</dc:creator>
      <dc:date>2025-02-24T16:23:16Z</dc:date>
    </item>
  </channel>
</rss>

