# How do get synthetic monitor availabililty from API?

**URL:** <https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100>\
**Category:** Dynatrace API\
**Tags:** synthetic-monitoring, dynatrace-api\
**Created:** [October 16, 2023, 1:40pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100 "2023-10-16T13:40:42Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 16, 2023, 1:40pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/1 "2023-10-16T13:40:42Z")

</div>

I would like to query the API with the id of a specific synthetic monitor and get the availability for the current day, for the last 7 days, for the last 30 days and for the last 90 days.

The API documentation indicates that general information about a monitor is available, but I can’t find any documenation on how to get the availability numbers.

Is this possible through the API?

---

<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:** [October 16, 2023, 2:22pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/2 "2023-10-16T14:22:09Z")

</div>

Hi [@DuaneRoelands](https://community.dynatrace.com/user/42547) , you can achieve this with the Get metric data points API: [Metrics API - GET metric data points — Dynatrace Docs](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/get-data-points)

And use the builtin metrics for Synthetic Monitors, [Built-in classic metrics — Dynatrace Docs](https://www.dynatrace.com/support/help/observe-and-explore/metrics/built-in-metrics#synthetic-monitoring)

Example, querying an HTTP monitor ID from last 30 days:

```markup
curl --location 'https://tenant.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin%3Asynthetic.http.availability.location.total%3Afilter(and(or(in(%22dt.entity.http_check%22%2CentitySelector(%22type(http_check)%2CentityId(~%22HTTP_CHECK-B97FBA280E3DC655~%22)%22)))))%3AsplitBy(%22dt.entity.http_check%22%2C%22dt.entity.synthetic_location%22)%3Asort(value(auto%2Cdescending))' \ --header 'Authorization: Api-token dt0c01.4OHVEPBHJGFYCVRCPHAI4FU4.tokenwithrightscope'

```

result:

```markup
{
    "totalCount": 1,
    "nextPageKey": null,
    "resolution": "30d",
    "result": [
        {
            "metricId": "builtin:synthetic.http.availability.location.total:filter(and(or(in(\"dt.entity.http_check\",entitySelector(\"type(http_check),entityId(~\"HTTP_CHECK-B97FBA280E3DC655~\")\"))))):splitBy(\"dt.entity.http_check\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
            "dataPointCountRatio": 0.0,
            "dimensionCountRatio": 1.0E-5,
            "data": [
                {
                    "dimensions": [
                        "HTTP_CHECK-B97FBA280E3DC655",
                        "SYNTHETIC_LOCATION-27E967621146D2EC"
                    ],
                    "dimensionMap": {
                        "dt.entity.synthetic_location": "SYNTHETIC_LOCATION-27E967621146D2EC",
                        "dt.entity.http_check": "HTTP_CHECK-B97FBA280E3DC655"
                    },
                    "timestamps": [
                        1697500800000
                    ],
                    "values": [
                        99.71761587744338
                    ]
                }
            ]
        }
    ]
}

```

where:

- from=now-30d
  - query last 30 days

- resolution=30d
  - get the resolution of one single value with the average of last 30 days

- metricSelector=builtin:synthetic.http.availability.location.total
  - that’s the metric selector where you can filter by a specific Monitor ID, work on the split by locations, if requried, etc, you can go crazy here.

Try and let us know.

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 2:17pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/3 "2023-10-18T14:17:13Z")

</div>

Can’t get data using this method.&nbsp; Steps:

Browsed through the Dynatrace UI to a synthetic at this URL:

```markup
https://{environmentid}.live.dynatrace.com/ui/browser-monitor/SYNTHETIC_TEST-6F96250FB9911AAC?gtf=-2h&gf=all

```

Took the “SYNTHETIC\_TEST-6F96250FB9911AAC” value from that URL and plugged into the URL described above:

```markup
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.http.availability.location.total:filter(and(or(in("dt.entity.http_check",entitySelector("type(http_check),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.http_check","dt.entity.synthetic_location"):sort(value(auto,descending))

```

Got the following JSON response:

```markup
{
    "totalCount": 0,
    "nextPageKey": null,
    "resolution": "30d",
    "result": [
        {
            "metricId": "builtin:synthetic.http.availability.location.total:filter(and(or(in(\"dt.entity.http_check\",entitySelector(\"type(http_check),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.http_check\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
            "dataPointCountRatio": 0.0,
            "dimensionCountRatio": 0.0,
            "data": []
        }
    ]
}

```

What am I missing?

---

<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:** [October 18, 2023, 5:16pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/4 "2023-10-18T17:16:14Z")

</div>

Hi [@DuaneRoelands](https://community.dynatrace.com/user/42547) , since you want to retrieve data from a Browser Monitor, you need to replace the metric to its respective entity.

from: builtin:synthetic.http.availability.location.total

to: builtin:synthetic.browser.availability.location.total

```markup
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test","dt.entity.synthetic_location"):sort(value(auto,descending))

```

Try and let us know.

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 5:23pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/5 "2023-10-18T17:23:43Z")

</div>

```markup
{
    "totalCount": 0,
    "nextPageKey": null,
    "resolution": "30d",
    "warnings": [
        "The dimension key `dt.entity.synthetic_location` has been referenced, but the metric has no such key."
    ],
    "result": [
        {
            "metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\",\"dt.entity.synthetic_location\"):sort(value(auto,descending))",
            "dataPointCountRatio": 0.0,
            "dimensionCountRatio": 2.0E-5,
            "data": [],
            "warnings": [
                "The dimension key `dt.entity.synthetic_location` has been referenced, but the metric has no such key."
            ]
        }
    ]
}

```

---

<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:** [October 18, 2023, 5:29pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/6 "2023-10-18T17:29:21Z")

</div>

Sorry, [@DuaneRoelands](https://community.dynatrace.com/user/42547) my mistake.

try this:

```markup
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test","dt.entity.geolocation"):sort(value(auto,descending))

```

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 5:39pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/7 "2023-10-18T17:39:37Z")

</div>

Almost there.&nbsp; How can I get ONLY the dimension that includes the availability without the GEOLOCATION value?

---

<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:** [October 18, 2023, 6:29pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/8 "2023-10-18T18:29:27Z")

</div>

Just remove it from the splitby condition

```markup
https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?from=now-30d&resolution=30d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test"):sort(value(auto,descending))

```

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 6:36pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/9 "2023-10-18T18:36:46Z")

</div>

Why are there two values in the result?

```markup
{
    "totalCount": 1,
    "nextPageKey": null,
    "resolution": "30d",
    "result": [
        {
            "metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\"):sort(value(auto,descending))",
            "dataPointCountRatio": 0.0,
            "dimensionCountRatio": 2.0E-5,
            "data": [
                {
                    "dimensions": [
                        "SYNTHETIC_TEST-6F96250FB9911AAC"
                    ],
                    "dimensionMap": {
                        "dt.entity.synthetic_test": "SYNTHETIC_TEST-6F96250FB9911AAC"
                    },
                    "timestamps": [
                        1695081600000,
                        1697673600000
                    ],
                    "values": [
                        99.65797381270639,
                        100
                    ]
                }
            ]
        }
    ]
}

```

---

<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:** [October 18, 2023, 7:18pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/10 "2023-10-18T19:18:18Z")

</div>

That’s due to the timestamp from and the resolution. Try do use a higher resolution , like resolution=31d

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 7:27pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/11 "2023-10-18T19:27:44Z")

</div>

I’m not sure I understand.&nbsp; If the from is now-30 and the resolution is 30, I would expect to only get one value back.

What’s the right way to get a single value for the past 30 days (or any specific time period like 7 days or 90 days?).

---

<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:** [October 18, 2023, 7:34pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/12 "2023-10-18T19:34:57Z")

</div>

That’s because now-30d is more than 30d, (30 days and few hours), and when you set the resolution to 30d you still have some extra points to be captured, so you get two values.

Setting the resolution to a higher number than the from will get you one single data point then.

from=now-30d, resolution=31d

from=now-7d, resolution=8d

from=now-90d, resolution=91d

---

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [October 18, 2023, 7:42pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/13 "2023-10-18T19:42:48Z")

</div>

from=now-90d, resolution=91d returns multiple values.

```markup
/api/v2/metrics/query?from=now-90d&resolution=91d&metricSelector=builtin:synthetic.browser.availability.location.total:filter(and(or(in("dt.entity.synthetic_test",entitySelector("type(synthetic_test),entityId(~"SYNTHETIC_TEST-6F96250FB9911AAC~")"))))):splitBy("dt.entity.synthetic_test"):sort(value(auto,descending))

```

```markup
{
    "totalCount": 1,
    "nextPageKey": null,
    "resolution": "91d",
    "result": [
        {
            "metricId": "builtin:synthetic.browser.availability.location.total:filter(and(or(in(\"dt.entity.synthetic_test\",entitySelector(\"type(synthetic_test),entityId(~\"SYNTHETIC_TEST-6F96250FB9911AAC~\")\"))))):splitBy(\"dt.entity.synthetic_test\"):sort(value(auto,descending))",
            "dataPointCountRatio": 0.0,
            "dimensionCountRatio": 2.0E-5,
            "data": [
                {
                    "dimensions": [
                        "SYNTHETIC_TEST-6F96250FB9911AAC"
                    ],
                    "dimensionMap": {
                        "dt.entity.synthetic_test": "SYNTHETIC_TEST-6F96250FB9911AAC"
                    },
                    "timestamps": [
                        1690156800000,
                        1698019200000
                    ],
                    "values": [
                        100,
                        99.88410972041746
                    ]
                }
            ]
        }
    ]
}

```

---

<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:** [October 18, 2023, 8:54pm UTC](https://community.dynatrace.com/t/how-do-get-synthetic-monitor-availabililty-from-api/42100/14 "2023-10-18T20:54:14Z")

</div>

Try a higher resolution then. resolution=95d.
