# Creating a metric event via APIv2: "No scope generator registered"

**URL:** <https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253>\
**Category:** Alerting\
**Tags:** dynatrace-managed, anomaly-detection, problems-classic\
**Created:** [November 11, 2022, 4:33pm UTC](https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253 "2022-11-11T16:33:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJimenez](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@CJimenez](https://community.dynatrace.com/u/CJimenez)\
**Post date:** [November 11, 2022, 4:33pm UTC](https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253/1 "2022-11-11T16:33:48Z")

</div>

Hi,

I have been using the settings API v2 to create anomaly detection for process availability alerts.

I am now trying to apply the same process to create metric event alerts (formerly known and custom events for alerting).

However, I get an error when trying to post to the settings API

[https://xxxxx.live.dynatrace.com/e/xxxxx/api/v2/settings/objects?validateOnly=true](https://xxxxx.live.dynatrace.com/e/xxxxx/api/v2/settings/objects?validateOnly=true)

[&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“schemaId”:&nbsp;“builtin:anomaly-detection.metric-events”,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“value”:&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“enabled”:&nbsp;true,xxxxxxxxx---RESPONSE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“error”:&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“code”:&nbsp;404,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“message”:&nbsp;“No&nbsp;scope&nbsp;generator&nbsp;registered&nbsp;for&nbsp;schema&nbsp;builtin:anomaly-detection.metric-events”&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},I’m only guessing, but does that mean there is currently no implementation of the metric-event scope within the settings API v2?

---

<div class="post-metadata">

**Author:** ![rgarzon1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rgarzon1/32/11844_2.png) [@rgarzon1](https://community.dynatrace.com/u/rgarzon1)\
**Post date:** [November 12, 2022, 6:19pm UTC](https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253/2 "2022-11-12T18:19:39Z")

</div>

HI cjimenez

maybe its something else. i just try the schema and works

 ![rgarzon1_0-1668277068365.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/b/5bf5b19897fdba3aa5a025c9f87946c6bf08d1cf.png)

maybe the version of the manage ui ? idk i am guessing..

im using SaaS: dynatrace version 1.254.92.20221109-192319

hope it helps

have fun

---

<div class="post-metadata">

**Author:** ![CJimenez](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@CJimenez](https://community.dynatrace.com/u/CJimenez)\
**Post date:** [November 15, 2022, 8:41am UTC](https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253/3 "2022-11-15T08:41:00Z")

</div>

Hi,

Thanks for your response, yes, I get the same when I query the API but does not accept a POST

This works fine:  
GET https://{your-domain}.live.dynatrace.com/e/{your-domain}/api/v2/settings/objects?schemaIds=builtin:anomaly-detection.metric-events

However, this returns the error “No&nbsp;scope&nbsp;generator&nbsp;registered&nbsp;for&nbsp;schema&nbsp;builtin:anomaly-detection.metric-events”:

POST&nbsp;https://{your-domain}&nbsp;.live.dynatrace.com/e/{your-domain}&nbsp;/api/v2/settings/objects?validateOnly=true

With JSON payload:

[  
{  
“schemaId”: “builtin:anomaly-detection.metric-events”,  
“schemaVersion”: “1.0.1”,  
“value”: {  
“enabled”: true,  
“summary”: “TEST METRIC EVENT”,  
“queryDefinition”: {  
“type”: “METRIC\_KEY”,  
“metricKey”: “builtin:host.disk.usedPct”,  
“aggregation”: “MAX”,  
“entityFilter”: {  
“dimensionKey”: “dt.entity.host”,  
“conditions”: [  
{  
“type”: “TAG”,  
“operator”: “EQUALS”,  
“value”: “TEST\_TAG”  
}  
]  
},  
“dimensionFilter”: []  
},  
“modelProperties”: {  
“type”: “STATIC\_THRESHOLD”,  
“threshold”: 80.0,  
“alertOnNoData”: false,  
“alertCondition”: “ABOVE”,  
“violatingSamples”: 3,  
“samples”: 5,  
“dealertingSamples”: 5  
},  
“eventTemplate”: {  
“title”: “TEST METRIC EVENT”,  
“description”: “Testing API creation of metric event”,  
“eventType”: “RESOURCE”,  
“davisMerge”: true,  
“metadata”: []  
},  
“eventEntityDimensionKey”: “dt.entity.host”  
}  
}  
]

---

<div class="post-metadata">

**Author:** ![CJimenez](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@CJimenez](https://community.dynatrace.com/u/CJimenez)\
**Post date:** [November 23, 2022, 6:18pm UTC](https://community.dynatrace.com/t/creating-a-metric-event-via-apiv2-no-scope-generator-registered/37253/4 "2022-11-23T18:18:40Z")

</div>

Found the issue for those facing similar:

The issue was the missing scope. For other settings that relate to an entity, you need to provide the entity ID as the scope. But in the case of Metric Events, the scope needs to be ‘environment’ as it does not link to a specific entity.
