# API metric/query - how to return just one result (data point)

**URL:** <https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [January 28, 2022, 5:53pm UTC](https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922 "2022-01-28T17:53:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct\_27](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ct_27/32/10499_2.png) [@ct\_27](https://community.dynatrace.com/u/ct_27)\
**Post date:** [January 28, 2022, 5:53pm UTC](https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922/1 "2022-01-28T17:53:04Z")

</div>

I’m trying to use the API to pull back the latest data point value for a given metric.&nbsp; I’ve tried playing with transforms and resolutions. I can get it down to 2 metrics. But any suggestions on how to just get the latest datapoint for a given metric on a given host?

We’re trying to integrate two monitoring systems by sending metrics out of DT and into the other monitoring tool using its APIs.

[https://xxxxxx.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Ahost.cpu.system&resolution=2&entitySelector=type("HOST")%2CentityName("xxxxxxxxx")](https://xxxxxx.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Ahost.cpu.system&resolution=2&entitySelector=type%28%22HOST%22%29%2CentityName%28%22xxxxxxxxx%22%29)

```auto
<span>{</span>
  <span>"totalCount"</span><span>:</span> <span>1</span><span>,</span>
  <span>"nextPageKey"</span><span>:</span> <span>null</span><span>,</span>
  <span>"resolution"</span><span>:</span> <span>"1h"</span><span>,</span>
  <span>"result"</span><span>:</span> <span>[</span>
    <span>{</span>
      <span>"metricId"</span><span>:</span> <span>"builtin:host.cpu.system"</span><span>,</span>
      <span>"data"</span><span>:</span> <span>[</span>
        <span>{</span>
          <span>"dimensions"</span><span>:</span> <span>[</span>
            <span>"HOST-xxxxx"</span>
          <span>]</span><span>,</span>
          <span>"dimensionMap"</span><span>:</span> <span>{</span>
            <span>"dt.entity.host"</span><span>:</span> <span>"HOST-xxxxx"</span>
          <span>}</span><span>,</span>
          <span>"timestamps"</span><span>:</span> <span>[</span>
            <span>1643385600000</span><span>,</span>
            <span>1643389200000</span><span>,</span>
            <span>1643392800000</span>
          <span>]</span><span>,</span>
          <span>"values"</span><span>:</span> <span>[</span>
            <span>1</span><span>.</span><span>8281565772162542</span><span>,</span>
            <span>1</span><span>.</span><span>7218984444936116</span><span>,</span>
            <span>1</span><span>.</span><span>766819120298886</span>
          <span>]</span>
        <span>}</span>
      <span>]</span>
    <span>}</span>
  <span>]</span>
<span>}</span>

```

---

<div class="post-metadata">

**Author:** ![edward-buckler](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/edward-buckler/32/15481_2.png) [@edward-buckler](https://community.dynatrace.com/u/edward-buckler)\
**Post date:** [January 28, 2022, 7:28pm UTC](https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922/2 "2022-01-28T19:28:06Z")

</div>

Hello,

OK assuming you can’t use whatever is running the API to grab the first element you can do something like this:

```markup
curl -X GET "https://XXXXXXXX.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Ahost.cpu.system&from=now-2m%2Fm&to=now-1m%2Fm&entitySelector=type%28HOST%29%2CentityId%28HOST-XXXXXXXXXXXXXXXX%29" -H "accept: application/json; charset=utf-8" -H "Authorization: Api-Token [TOKEN]"

```

Effectively I am just using the timeframe selector to get the last datapoint:

 ![edwardbuckler_1-1643398056346.png](https://global.discourse-cdn.com/dynatrace/original/2X/9/953550989013fc502e119e48f35bd6f8341a27bc.png)

The response would look like this:

```markup
{
  "totalCount": 1,
  "nextPageKey": null,
  "resolution": "1m",
  "result": [
    {
      "metricId": "builtin:host.cpu.system",
      "data": [
        {
          "dimensions": [
            "HOST-XXXXXXXXXXXXXXXX"
          ],
          "dimensionMap": {
            "dt.entity.host": "HOST-XXXXXXXXXXXXXXXX"
          },
          "timestamps": [
            1643397300000
          ],
          "values": [
            0.32281724611918133
          ]
        }
      ]
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![ct\_27](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ct_27/32/10499_2.png) [@ct\_27](https://community.dynatrace.com/u/ct_27)\
**Post date:** [January 28, 2022, 7:59pm UTC](https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922/3 "2022-01-28T19:59:15Z")

</div>

Thank you.&nbsp; That’s a fantastic solution.&nbsp; Much appreciated.

Dynatrace Developers:&nbsp; Any thoughts of having a “Last” resolution or Transformation to make this easier?

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [January 28, 2022, 8:19pm UTC](https://community.dynatrace.com/t/api-metric-query-how-to-return-just-one-result-data-point/33922/4 "2022-01-28T20:19:56Z")

</div>

[@ct\_27](https://community.dynatrace.com/user/38037)&nbsp;Try to add the “:lastReal” at the end of your metricselector query&nbsp;🙂.

Even if you remove the resolution, it will always get the last datapoint.
