<?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: Query on API - V1 to V2 in Dynatrace API</title>
    <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250198#M3248</link>
    <description>&lt;P&gt;If I am understanding your question properly, you're aiming to use the V2 API for the same purpose you used the V1, which in this case is to disable host monitoring based on certain conditions with a custom script.&lt;/P&gt;&lt;P&gt;I know this endpoint works for fetching hosts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl -X GET "https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type(HOST)" \
-H "Authorization: Api-Token &amp;lt;your-api-token&amp;gt;"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, you can use the settings/objects with the builtin:host.monitoring schema to update settings on a specific host.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/53941"&gt;@smartpraseetha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I am wondering what is the purpose of schema and how could we use in the same level as the previous API ?&lt;/P&gt;&lt;P&gt;Also is there any reference that I&amp;nbsp; can have the API -&amp;nbsp; /api/config/v1/hosts/{id}/monitoring&amp;nbsp; in&amp;nbsp; V2 version&amp;nbsp; ?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here's a python script I've successfully used before to disable monitoring of hosts based on a condition, using the V2.&lt;/P&gt;&lt;P&gt;Essentialy, V2 uses a structured approach where settings are managed via configurations (schemas and settings objects).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

# Dynatrace environment and API token
dt_env = "placeholder"
api_token = "placeholder"

# Headers for API requests
headers = {
    "Authorization": f"Api-Token {api_token}",
    "Content-Type": "application/json"
}

# Define the condition function before using it
def some_condition(host):
    # Implement your condition logic here
    # Example: Disable monitoring for all hosts
    return True

# Step 1: Get all hosts (requires entities.read permission)
hosts_url = f"https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type(HOST)"
response = requests.get(hosts_url, headers=headers)
if response.status_code == 200:
    hosts = response.json().get('entities', [])
    print("Fetched Hosts:")
    print(json.dumps(hosts, indent=2))
else:
    print(f"Failed to fetch hosts: {response.status_code} - {response.text}")
    hosts = []

# Step 2: Iterate over hosts and disable monitoring (requires settings.write permission)
for host in hosts:
    host_id = host['entityId']
    print(f"Processing host {host_id}")
    
    # Check some condition to decide whether to disable monitoring
    if some_condition(host):
        # Disable monitoring for the host
        settings_url = f"https://{environmentid}.live.dynatrace.com/api/v2/settings/objects"
        payload = [
            {
                "schemaId": "builtin:host.monitoring",
                "scope": host_id,  
                "value": {
                    "enabled": False  
                }
            }
        ]
        response = requests.post(settings_url, headers=headers, json=payload)
        if response.status_code == 200:
            print(f"Monitoring disabled for host {host_id}")
        else:
            print(f"Failed to disable monitoring for host {host_id}: {response.status_code} - {response.text}")
    else:
        print(f"Condition not met for host {host_id}, monitoring remains enabled")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2024 17:25:07 GMT</pubDate>
    <dc:creator>PedroSantos</dc:creator>
    <dc:date>2024-07-09T17:25:07Z</dc:date>
    <item>
      <title>Query on API - V1 to V2</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250161#M3247</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a custom script which stops the monitoring on the hosts based on some conditions.&lt;/P&gt;
&lt;P&gt;I am using 2 APIS the first API gets all the hosts - /entity/infrastructure/hosts/ and I made an iteration in a loop that it gets entity {id} for each host and it feeds that to the&amp;nbsp;second&amp;nbsp;API v1&amp;nbsp; - /api/config/v1/hosts/{id}/monitoring&lt;/P&gt;
&lt;P&gt;That is now V1 versions are in the&amp;nbsp; Deprecated state.&lt;/P&gt;
&lt;P&gt;The alternate option given is to Manage host monitoring settings for&amp;nbsp;/api/config/v1/hosts/{id}/monitoring is&amp;nbsp; via the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;settings endpoint&amp;nbsp;&lt;/SPAN&gt;with schemaId&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;builtin:host.monitoring&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;instead. But I dont get to see the same results to get the ways to pass the entity id nor get&amp;nbsp; the monitoring configuration of OneAgents.&lt;/P&gt;
&lt;P&gt;I am wondering what is the purpose of schema and how could we use in the same level as the previous API ?&lt;/P&gt;
&lt;P&gt;Also is there any reference that I&amp;nbsp; can have the API -&amp;nbsp; /api/config/v1/hosts/{id}/monitoring&amp;nbsp; in&amp;nbsp; V2 version&amp;nbsp; ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 12:56:42 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250161#M3247</guid>
      <dc:creator>smartpraseetha</dc:creator>
      <dc:date>2024-07-12T12:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Query on API - V1 to V2</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250198#M3248</link>
      <description>&lt;P&gt;If I am understanding your question properly, you're aiming to use the V2 API for the same purpose you used the V1, which in this case is to disable host monitoring based on certain conditions with a custom script.&lt;/P&gt;&lt;P&gt;I know this endpoint works for fetching hosts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl -X GET "https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type(HOST)" \
-H "Authorization: Api-Token &amp;lt;your-api-token&amp;gt;"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, you can use the settings/objects with the builtin:host.monitoring schema to update settings on a specific host.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/53941"&gt;@smartpraseetha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I am wondering what is the purpose of schema and how could we use in the same level as the previous API ?&lt;/P&gt;&lt;P&gt;Also is there any reference that I&amp;nbsp; can have the API -&amp;nbsp; /api/config/v1/hosts/{id}/monitoring&amp;nbsp; in&amp;nbsp; V2 version&amp;nbsp; ?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here's a python script I've successfully used before to disable monitoring of hosts based on a condition, using the V2.&lt;/P&gt;&lt;P&gt;Essentialy, V2 uses a structured approach where settings are managed via configurations (schemas and settings objects).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

# Dynatrace environment and API token
dt_env = "placeholder"
api_token = "placeholder"

# Headers for API requests
headers = {
    "Authorization": f"Api-Token {api_token}",
    "Content-Type": "application/json"
}

# Define the condition function before using it
def some_condition(host):
    # Implement your condition logic here
    # Example: Disable monitoring for all hosts
    return True

# Step 1: Get all hosts (requires entities.read permission)
hosts_url = f"https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type(HOST)"
response = requests.get(hosts_url, headers=headers)
if response.status_code == 200:
    hosts = response.json().get('entities', [])
    print("Fetched Hosts:")
    print(json.dumps(hosts, indent=2))
else:
    print(f"Failed to fetch hosts: {response.status_code} - {response.text}")
    hosts = []

# Step 2: Iterate over hosts and disable monitoring (requires settings.write permission)
for host in hosts:
    host_id = host['entityId']
    print(f"Processing host {host_id}")
    
    # Check some condition to decide whether to disable monitoring
    if some_condition(host):
        # Disable monitoring for the host
        settings_url = f"https://{environmentid}.live.dynatrace.com/api/v2/settings/objects"
        payload = [
            {
                "schemaId": "builtin:host.monitoring",
                "scope": host_id,  
                "value": {
                    "enabled": False  
                }
            }
        ]
        response = requests.post(settings_url, headers=headers, json=payload)
        if response.status_code == 200:
            print(f"Monitoring disabled for host {host_id}")
        else:
            print(f"Failed to disable monitoring for host {host_id}: {response.status_code} - {response.text}")
    else:
        print(f"Condition not met for host {host_id}, monitoring remains enabled")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 17:25:07 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250198#M3248</guid>
      <dc:creator>PedroSantos</dc:creator>
      <dc:date>2024-07-09T17:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Query on API - V1 to V2</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250219#M3249</link>
      <description>&lt;P&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/77112"&gt;@PedroSantos&lt;/a&gt;&amp;nbsp;Thank you very much for the insights on the schema id so that means its needs to be combined with another api&amp;nbsp;/api/v2/settings/objects" to pass the entity ids. It is clear to me now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 07:29:48 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/250219#M3249</guid>
      <dc:creator>smartpraseetha</dc:creator>
      <dc:date>2024-07-10T07:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Query on API - V1 to V2</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/254801#M3359</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/77112"&gt;@PedroSantos&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My view here is that&amp;nbsp; these changes of APIS to schemas seems to be not very useful to meet a variety of extracts with conditions. In my case it doesn't allow to have the several filters or conditions based on the parent API which I intended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example the host monitoring API referred here&amp;nbsp; - I couldn't ( use multiple conditions) example&amp;nbsp; to use my hosts in iteration mode - Condition to check monitoring mode and monitoring state 2 conditions, to make this logic effective I need to call 2 schemas which i found making the logic extensive. So I moved ahead with 1 condition to check only monitoring state from the API -hosts_url = f"https://{environmentid}.live.dynatrace.com/api/v2/entities?pageSize=1000&amp;amp;entitySelector=type(HOST)mzID()&amp;amp;from=now-1h&amp;amp;fields=properties.STATE&lt;/P&gt;&lt;P&gt;Take those hosts based on that condition then iterate it, there was the problem&amp;nbsp;&amp;nbsp;i found it complicated as the schemas with GET and POST on have different values expected to be passed in the JSON.&lt;/P&gt;&lt;P&gt;This was my GET API&amp;nbsp; - &lt;A href="https://environment/api/v2/settings/objects?schemaIds=builtin%3Ahost.monitoring&amp;amp;fields=objectId%2Cvalue%2Csummary%2Cscope&amp;amp;filter=value.enabled%20%3D%20true&amp;amp;pageSize=500" target="_blank" rel="noopener"&gt;https://environment/api/v2/settings/objects?schemaIds=builtin%3Ahost.monitoring&amp;amp;fields=objectId%2Cvalue%2Csummary%2Cscope&amp;amp;filter=value.enabled%20%3D%20true&amp;amp;pageSize=500&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$payload= @{schemaId=$builtinmonitoring&lt;BR /&gt;scope=$host_id&lt;BR /&gt;value=@{enabled=$enabled}&lt;BR /&gt;}|ConvertTo-Json&lt;/P&gt;&lt;P&gt;Write-host $payload&lt;BR /&gt;$response = Invoke-RestMethod -Uri $settings_url -Headers $headers -Method Post -Body $payload&lt;/P&gt;&lt;P&gt;And my POST API&amp;nbsp; as $response with&amp;nbsp;&lt;SPAN&gt;JSON body of the request as below. Which means the results of&amp;nbsp; GET&lt;/SPAN&gt; Schema&amp;nbsp; with the value.enabled&amp;nbsp; cannot be passed to Stop the monitoring using POST or PUT&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;settings/objects&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;  {
    &lt;SPAN class=""&gt;"externalId"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"string"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"insertAfter"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"Y2ktaGd="&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"objectId"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"Y2ktaGd"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"schemaId"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"builtin:container.built-in-monitoring-rule"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"schemaVersion"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"1.0.0"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"scope"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"HOST-D"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;    &lt;SPAN class=""&gt;"value"&lt;/SPAN&gt;&lt;SPAN&gt;: {&lt;/SPAN&gt;      &lt;SPAN class=""&gt;"autoMonitoring"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;
    }
  }
]&lt;/PRE&gt;&lt;P&gt;There is no object called value.enabled = false like in GET&amp;nbsp; to be passed to POST/PUT&amp;nbsp; as there it is referred as&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;"value": {&lt;/SPAN&gt;&lt;SPAN&gt;    "autoMonitoring": true&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;It seems to be more complicated for simple logics. Can you guide how to use schema with&amp;nbsp; GET and POST in stopping monitoring of the hosts ?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 12:20:44 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/254801#M3359</guid>
      <dc:creator>smartpraseetha</dc:creator>
      <dc:date>2024-09-03T12:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Query on API - V1 to V2</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/278771#M3786</link>
      <description>&lt;P&gt;This good if you have control to introduce a man in the middle and deliver this component in Python, However, we are depending on&amp;nbsp;&lt;A class="" title="Ctrl + Click to open https://{environmentid}.live.dynatrace.com/api/v1/entity/infrastructure/hosts in a new tab" href="https://{environmentid}.live.dynatrace.com/api/v1/entity/infrastructure/hosts" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN&gt;api/v1/entity/infrastructure/hosts&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;to use it an extract in our CMDB, are you sure there is no v2 of the one call approach.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 11:57:26 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Query-on-API-V1-to-V2/m-p/278771#M3786</guid>
      <dc:creator>MarwanC</dc:creator>
      <dc:date>2025-06-05T11:57:26Z</dc:date>
    </item>
  </channel>
</rss>

