<?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: DQL query syntax while using in API calls in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/DQL-query-syntax-while-using-in-API-calls/m-p/293251#M3053</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;try this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch dt.entity.host
| filterOut isMonitoringCandidate == true or standalone == true
| lookup [
    timeseries m1 = max(dt.host.availability, rollup: sum),
      filter: availability.state == "up",
      by: { availability.state, dt.entity.host },
      from: now() - 24h,
      to: now() - 2m
    | parse replaceString(toString(m1), "null", "0"), "'['ARRAY{ DOUBLE:i ', '}{1,10000}:m1Pop"
    | fieldsAdd intervalToMinutes = toLong(interval) / 60 / power(10, 9)
    | fieldsAdd availability = toDouble(arraySum(m1Pop) / arraySize(m1Pop) * 100) / intervalToMinutes
  ],
  sourceField: id,
  lookupField: dt.entity.host,
  fields: { availability }
| fields id, availability = coalesce(availability, 0)
| summarize avg(availability)&lt;/LI-CODE&gt;&lt;P&gt;The query works locally because $dt_timeframe_from and $dt_timeframe_to are dashboard-only variables. They are not resolved when executing DQL via the Query API, which results in a 400 Bad Request.&lt;/P&gt;&lt;P&gt;Remove $dt_timeframe_from / $dt_timeframe_to from the DQL&lt;/P&gt;&lt;P&gt;Use now() - … in the query or pass the timeframe via the query:execute request body&lt;/P&gt;&lt;P&gt;Replace the parse """ ... """ with a normal quoted string ("...") to avoid JSON parsing issues&lt;/P&gt;&lt;P&gt;After these changes, the query executes correctly via the API.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="t_pawlak_0-1768765729511.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31663iF1B086D92A5E1413/image-size/medium?v=v2&amp;amp;px=400" role="button" title="t_pawlak_0-1768765729511.png" alt="t_pawlak_0-1768765729511.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Jan 2026 19:49:05 GMT</pubDate>
    <dc:creator>t_pawlak</dc:creator>
    <dc:date>2026-01-18T19:49:05Z</dc:date>
    <item>
      <title>DQL query syntax while using in API calls</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-query-syntax-while-using-in-API-calls/m-p/293240#M3052</link>
      <description>&lt;P&gt;I am trying to use this query to fetch remote environment data, but not working for remote environment through API call. But this works&amp;nbsp;in local environment to get the host availability,&amp;nbsp;&lt;/P&gt;&lt;P&gt;fetch dt.entity.host&lt;BR /&gt;| filterOut isMonitoringCandidate == true or standalone == true&lt;BR /&gt;| lookup [&lt;BR /&gt;timeseries m1=max(dt.host.availability, rollup: sum),&lt;BR /&gt;filter: availability.state == "up",&lt;BR /&gt;by: {availability.state,dt.entity.host},&lt;BR /&gt;from: toTimestamp($dt_timeframe_from),&lt;BR /&gt;to: toTimestamp($dt_timeframe_to) - 2m&lt;BR /&gt;| parse replaceString(toString(m1),"null","0"), """'['ARRAY{ DOUBLE:i ', '}{1,10000}:m1Pop"""&lt;BR /&gt;| fieldsAdd intervalToMinutes = toLong(interval) / 60 / power(10, 9)&lt;BR /&gt;| fieldsAdd availability = toDouble(arraySum(m1Pop) / arraySize(m1Pop) * 100) / intervalToMinutes&lt;BR /&gt;], sourceField: id, lookupField: dt.entity.host, fields: {availability}&lt;BR /&gt;| fields id, availability = coalesce(availability, 0)&lt;BR /&gt;| summarize avg(availability)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to parse this query in the API call section, I tried giving this like other queries but getting 400 Bad request error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;const credentialId = "CREDENTIALS_VAULT-XXXXXXXX"; // Replace with your credential vault ID.&lt;BR /&gt;const url = "&lt;A href="https://{environmentid}.apps.dynatrace.com/platform/storage/query/v1/query:execute" target="_blank" rel="noopener"&gt;https://{environmentid}.apps.dynatrace.com/platform/storage/query/v1/query:execute&lt;/A&gt;"; // Replace with API URL.&lt;BR /&gt;const query = "&amp;lt;how to give the above DQL query as string here&amp;gt; "; // Replace with your query.&lt;/P&gt;&lt;P&gt;Could you please help? Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jan 2026 12:41:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-query-syntax-while-using-in-API-calls/m-p/293240#M3052</guid>
      <dc:creator>harinhs</dc:creator>
      <dc:date>2026-01-17T12:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: DQL query syntax while using in API calls</title>
      <link>https://community.dynatrace.com/t5/DQL/DQL-query-syntax-while-using-in-API-calls/m-p/293251#M3053</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;try this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch dt.entity.host
| filterOut isMonitoringCandidate == true or standalone == true
| lookup [
    timeseries m1 = max(dt.host.availability, rollup: sum),
      filter: availability.state == "up",
      by: { availability.state, dt.entity.host },
      from: now() - 24h,
      to: now() - 2m
    | parse replaceString(toString(m1), "null", "0"), "'['ARRAY{ DOUBLE:i ', '}{1,10000}:m1Pop"
    | fieldsAdd intervalToMinutes = toLong(interval) / 60 / power(10, 9)
    | fieldsAdd availability = toDouble(arraySum(m1Pop) / arraySize(m1Pop) * 100) / intervalToMinutes
  ],
  sourceField: id,
  lookupField: dt.entity.host,
  fields: { availability }
| fields id, availability = coalesce(availability, 0)
| summarize avg(availability)&lt;/LI-CODE&gt;&lt;P&gt;The query works locally because $dt_timeframe_from and $dt_timeframe_to are dashboard-only variables. They are not resolved when executing DQL via the Query API, which results in a 400 Bad Request.&lt;/P&gt;&lt;P&gt;Remove $dt_timeframe_from / $dt_timeframe_to from the DQL&lt;/P&gt;&lt;P&gt;Use now() - … in the query or pass the timeframe via the query:execute request body&lt;/P&gt;&lt;P&gt;Replace the parse """ ... """ with a normal quoted string ("...") to avoid JSON parsing issues&lt;/P&gt;&lt;P&gt;After these changes, the query executes correctly via the API.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="t_pawlak_0-1768765729511.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/31663iF1B086D92A5E1413/image-size/medium?v=v2&amp;amp;px=400" role="button" title="t_pawlak_0-1768765729511.png" alt="t_pawlak_0-1768765729511.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jan 2026 19:49:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/DQL-query-syntax-while-using-in-API-calls/m-p/293251#M3053</guid>
      <dc:creator>t_pawlak</dc:creator>
      <dc:date>2026-01-18T19:49:05Z</dc:date>
    </item>
  </channel>
</rss>

