Analytics aggregates query rejects PT5M interval despite docs

HTTP/1.1 400 Bad Request
{
 "errors": [
 {
 "code": "invalid_query",
 "message": "group_by interval is not valid for the selected metrics. Valid intervals: 15m, 30m, 1h."
 }
 ]
}

Building a custom interval report via /api/v2/analytics/conversations/aggregates/query. Consumer contract expects 5-minute granularity, but provider rejects the groupBy interval string.

query:
 interval: PT5M
 groupBy:
 - queueId
 filter:
 and:
 - path: queueId
 operator: in
 value: [QUEUE_UUID]
 metrics:
 - name: talk
 - name: wait

Post request returns 400. Documentation states ISO 8601 duration is supported for custom intervals, yet validation fails. Removing interval and using interval: 5m works, but breaks the Pact verification for the consumer expecting the duration format. Is the Analytics endpoint enforcing a strict enum for intervals despite the docs? Or is there a specific include flag required to unlock custom durations?

Generally speaking, the group_by interval validation is strict about ISO 8601 duration formats and metric compatibility. The API rejects PT5M if the selected metrics don’t support that granularity or if the format isn’t exactly right.

First, check your metric list. Not all metrics support 5-minute intervals. For example, conversation/count works, but some detailed analytics metrics might only allow 15m, 30m, or 1h. If you’re using a metric that doesn’t support PT5M, the API will throw that exact error.

Second, ensure the interval string is strictly ISO 8601. PT5M is correct for 5 minutes, but sometimes SDKs or query builders mangle this. Try explicitly setting it in the JSON payload.

Here’s a working curl example with a compatible metric:

curl -X POST "https://api.mypurecloud.com/api/v2/analytics/conversations/aggregates/query" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
 "metrics": ["conversation/count"],
 "groupBy": ["interval"],
 "interval": "PT5M",
 "dateFrom": "2023-10-01T00:00:00.000Z",
 "dateTo": "2023-10-01T01:00:00.000Z"
}'

If you’re using the PureCloudPlatformClientV2 SDK, ensure you’re constructing the GroupBy object correctly. In TypeScript, it looks like this:

const groupBy = new platformClient.AnalyticsApi.GroupBy();
groupBy.interval = "PT5M";

Also, verify the dateFrom and dateTo range. If the range is smaller than the interval, the API might reject it. Ensure your time window is at least PT5M wide.

If you’re still hitting the error, try switching to PT15M to confirm the issue is specifically with the 5-minute interval. If PT15M works, then your metric choice is the culprit. Check the metric documentation for supported intervals. Some metrics, especially those involving agent performance, have stricter granularity requirements.

Finally, if you’re building this in Pulumi, ensure you’re not accidentally stringifying the object incorrectly. The payload must be a clean JSON object, not a stringified version of an object. Double-check your Pulumi resource definition for the analytics query.