Analytics API: 400 Bad Request on Conversations Aggregates Query in n8n

HTTP 400: Invalid request body. The query structure does not match the expected schema.

I am attempting to build a custom interval report using the Analytics Conversations Aggregates endpoint (/api/v2/analytics/conversations/aggregates) from an n8n HTTP node. My goal is to retrieve handle time metrics for a specific queue over the last 24 hours.

The request body I am sending is structured as follows:

{
 "query": {
 "groupBy": ["queue.id"],
 "interval": "P1D",
 "startTime": "2023-10-27T00:00:00.000Z",
 "endTime": "2023-10-28T00:00:00.000Z",
 "metrics": ["handleTime", "wrapupTime"]
 },
 "filters": {
 "queue.id": ["550e8400-e29b-41d4-a716-446655440000"]
 }
}

The API consistently returns a 400 error. I have verified the OAuth token is valid and has the analytics:report:read scope. The documentation suggests interval should be ISO 8601 duration, but I suspect the issue might lie in how I am nesting the filters object versus the query object.

Is there a specific schema requirement for the filters array that I am missing? Or is the groupBy field conflicting with the filter structure in this endpoint version?

Oh, this is a known issue…

The groupBys array in the body must strictly match the metricNames. If you ask for handleTime but group by user, the API throws a 400 because that aggregation isn’t valid for that metric combination. Check your metricDefinitions too. Here is the minimal valid payload structure:

{
 "dateFrom": "2023-10-25T00:00:00.000Z",
 "dateTo": "2023-10-26T00:00:00.000Z",
 "metricNames": [
 "handleTime"
 ],
 "groupBys": [
 "queue"
 ],
 "queryFilter": {
 "type": "or",
 "clauses": [
 {
 "type": "field",
 "field": "queueId",
 "operator": "equals",
 "values": ["your-queue-id-here"]
 }
 ]
 }
}

Ensure your n8n node is sending Content-Type: application/json or the parser will fail before even hitting the schema validation.