# Can I use API to realize Put Metric events setting?

**URL:** <https://community.dynatrace.com/t/can-i-use-api-to-realize-put-metric-events-setting/41209>\
**Category:** Dynatrace API\
**Tags:** dynatrace-managed, dynatrace-api\
**Created:** [August 15, 2023, 5:48am UTC](https://community.dynatrace.com/t/can-i-use-api-to-realize-put-metric-events-setting/41209 "2023-08-15T05:48:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanna](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@kanna](https://community.dynatrace.com/u/kanna)\
**Post date:** [August 15, 2023, 5:48am UTC](https://community.dynatrace.com/t/can-i-use-api-to-realize-put-metric-events-setting/41209/1 "2023-08-15T05:48:06Z")

</div>

Click the API on the page of Metric events, and the system gives the method of obtaining page data by default, but if I want to realize new Metric events through API, can it be realized? Because put/settings/objects/{objectid} in API V2.  
Updates an existing settings object and POST /settings/objects Creates a new settings object didn’t make it clear.

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [August 16, 2023, 12:54pm UTC](https://community.dynatrace.com/t/can-i-use-api-to-realize-put-metric-events-setting/41209/2 "2023-08-16T12:54:57Z")

</div>

I’m not 100% of the true ask of this question but If you are looking to Post new Custom Events for alerting, It can be done via the Environment V2 \> Settings - Objects, From there you will use&nbsp;builtin:anomaly-detection.metric-events as the Schema&nbsp;ID and then get the&nbsp;ID of the item you want. Thake that ID and get the settings of that object ID, edit and report it as needed or even create a net new set up via the&nbsp;Posting option.

 ![ChadTurner_0-1692190481169.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/b/cb42dc5caa3bcae53022320ba4f096b76bb5cb1d.png)

---

<div class="post-metadata">

**Author:** ![mark\_bley](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/mark_bley/32/20954_2.png) [@mark\_bley](https://community.dynatrace.com/u/mark_bley)\
**Post date:** [August 21, 2023, 11:28am UTC](https://community.dynatrace.com/t/can-i-use-api-to-realize-put-metric-events-setting/41209/3 "2023-08-21T11:28:13Z")

</div>

Creating a new metric event through the API can be achieved like follow:

(This is just a curl example with some dummy payload, you would need to adjust fields to your needs)

```markup
curl --location --request POST 'https://{environmentid}.live.dynatrace.com/api/v2/settings/objects?validateOnly=false' \
--header 'accept: application/json; charset=utf-8' \
--header 'Authorization: Api-Token dt0c01.5VXCARPRP52BZNJVBUDSMQA5....' \
--header 'Content-Type: application/json; charset=utf-8' \
--data-raw '[
{
  "scope": "environment",
  "schemaId": "builtin:anomaly-detection.metric-events",
    "value": {
    "enabled": false,
    "summary": "DEMO ALERT",
    "queryDefinition": {
      "type": "METRIC_KEY",
      "metricKey": "builtin:host.cpu.usage",
      "aggregation": "AVG",
      "entityFilter": {
        "conditions": []
      },
      "dimensionFilter": []
    },
    "modelProperties": {
      "type": "STATIC_THRESHOLD",
      "threshold": 1,
      "alertOnNoData": false,
      "alertCondition": "ABOVE",
      "violatingSamples": 1,
      "samples": 3,
      "dealertingSamples": 3
    },
    "eventTemplate": {
      "title": "DEMO TITLE",
      "description": "The {metricname} value of {severity} was {alert_condition} your custom threshold of {threshold}.",
      "eventType": "RESOURCE",
      "davisMerge": true,
      "metadata": []
    },
    "eventEntityDimensionKey": "dt.entity.host"
  }
}
]'

```

The response on successful creation looks like this:

```markup
[
    {
        "code": 200,
        "objectId": "vu9U3hXa3q0AAAABACdidWlsdGluOmFub21hbHktZGV0ZWN0aW9uLm1ldHJpYy1ldmVudHMABnRlbmFudAAGdGVuYW50ACRiN2JhOTU2Zi0xNTMwLTNiZTQtYWNiYS0zMjc5YThjODk3ZmG-71TeFdrerQ"
    }
]

```
