Trying to pull agent state history for the last 24 hours using the Reporting API. The goal is to calculate idle time per agent, but the query keeps failing with a 400 Bad Request.
I’ve checked the docs and the endpoint is GET /api/v2/reporting/queues/realtime but that’s for realtime. For history, I’m hitting GET /api/v2/reporting/agents/summary? No wait, that’s not right either. It’s GET /api/v2/reporting/agents/history.
Here is the cURL command I’m running:
curl -X GET "https://api.mypurecloud.com/api/v2/reporting/agents/history" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"interval": "PT1H",
"dateFrom": "2023-10-25T00:00:00.000Z",
"dateTo": "2023-10-26T00:00:00.000Z",
"view": "AGENT_STATE_HISTORY",
"groupings": ["agentId"]
}'
The response body says:
{
"code": "bad.request",
"message": "Invalid query parameters. The view 'AGENT_STATE_HISTORY' is not supported for this resource.",
"status": 400
}
I’ve tried changing the view to AGENT_DETAILS and QUEUE_AGENT_DETAILS but the data granularity isn’t right. I need state transitions (Ready, Not Ready, Wrap Up).
Is there a specific view name for state history? Or do I need to use the OData query string instead of the JSON body? The SDK examples show JSON bodies for most reporting calls, so I’m assuming that’s the standard.
Also, the dateFrom and dateTo are within the 30-day limit, so that shouldn’t be the issue. Just stuck on the view parameter.
The endpoint you’re hitting doesn’t exist, which is why you’re getting a 400. There is no /api/v2/reporting/agents/history. That path is completely made up. You need to use the Analytics API for historical data, not the Reporting API which is mostly for real-time or very short windows.
The correct path is POST /api/v2/analytics/agents/summary. It’s a POST because you’re sending a complex query body. The body needs to specify the dateRange, groupBy, and select fields. If you want idle time, you need to group by agent and select the wrapup or afterCallWork metrics, depending on how your org defines idle.
Here is a working cURL example. Replace the placeholders with your actual org details.
curl -X POST "https://api.mypurecloud.com/api/v2/analytics/agents/summary" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"dateRange": {
"type": "absolute",
"from": "2023-10-25T00:00:00.000Z",
"to": "2023-10-26T00:00:00.000Z"
},
"groupBy": ["agent"],
"select": ["agent.id", "agent.name", "wrapup", "afterCallWork"],
"interval": "hour"
}'
The dateRange object is critical. You can’t just pass a string. It needs that type, from, and to structure. Also, make sure your token has the analytics:view scope. If you’re using the Embeddable Client App SDK, you can grab the token from the platformClient instance. Just call platformClient.Auth.getAccessToken() and use that in your header.
One gotcha: the API returns buckets. You’ll get an array of results, one for each hour in the range. You need to sum up the wrapup or afterCallWork fields across all buckets for a single agent to get the total idle time. Don’t forget to handle pagination if you’re querying a large date range. The response will have a nextPage token if there’s more data.