# Resolve constraint issues with metricSelector in API

**URL:** <https://community.dynatrace.com/t/resolve-constraint-issues-with-metricselector-in-api/49030>\
**Category:** Automations\
**Tags:** workflows, automations, dynatrace-api\
**Created:** [November 22, 2024, 4:44pm UTC](https://community.dynatrace.com/t/resolve-constraint-issues-with-metricselector-in-api/49030 "2024-11-22T16:44:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajithsaranya](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@ajithsaranya](https://community.dynatrace.com/u/ajithsaranya)\
**Post date:** [November 22, 2024, 4:44pm UTC](https://community.dynatrace.com/t/resolve-constraint-issues-with-metricselector-in-api/49030/1 "2024-11-22T16:44:45Z")

</div>

Hi Team,

We are trying to automate metrics for our workloads and see below exception with 400 code

Exception in thread “main” java.io.IOException:

Error Code: 400

URL: https://\<\>/query?from=2024-11-21T17:30:01.000&to=2024-11-21T20:01:59.000&metricSelector=builtin:containers.cpu.usagePercent:filter(and(in(“dt.entity.container\_group\_instance”,entitySelector(“type(container\_group\_instance),entityName(~”\*\*\*\*\*\*\*\*-~“)”)))):splitBy(“dt.entity.container\_group\_instance”):avg:auto:sort(value(avg,descending)):limit(10)

Response Text: {“error”:{“code”:400,“message”:“Constraints violated.”,“constraintViolations”:[{“path”:“nextPageKey”,“message”:“expected one of nextPageKey or metricSelector to be specified”,“parameterLocation”:“QUERY”,“location”:null}]}}

\<\> is host, \*\* is our workload, masking it for data privacy.

metricSelector is mentioned in URL yet seeing same errorcode, adding pageKey as suggested shows combination is not supported. Stuck here please help

Please note that the same call works using postman

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [November 27, 2024, 9:33am UTC](https://community.dynatrace.com/t/resolve-constraint-issues-with-metricselector-in-api/49030/2 "2024-11-27T09:33:57Z")

</div>

Hello&nbsp;[@ajithsaranya](https://community.dynatrace.com/user/67700)

Kindly ensure the specified parameters in the Api call meets the defined parameters in Dynatrace doc to avoid exposure to the highlighted error:

- [Metrics API - Metric selector — Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/metric-v2/metric-selector)
- [Metrics API v2 - Best practices — Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/metric-v2/best-practices)
- [Metrics API - Examples and use cases — Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/metric-v2/examples)

Hoping it adds value

Regards,

Peter
