Null wrapUpCode in analytics detail queries

Having some issues getting my configuration to work… I am querying /api/v2/analytics/details/agents with groupBy: wrapUpCode but the results consistently return null for the code field even though the data exists in the UI.

I have verified the time range and agent filters are correct. The JSON payload includes the standard interval and metric definitions, yet the wrapUpCode bucket remains empty or null.

Is this a known limitation of the detail query endpoint, or am I missing a specific parameter in the request body?

According to the docs, they say that wrapUpCode is not a standard metric but a dimension that requires specific configuration in the query payload. If you are just grouping by it without defining the metrics correctly, the API returns null because it doesn’t know what data to aggregate. I hit this exact issue last week while scripting a bulk report for our Sydney team. The issue usually stems from how the metrics array is structured relative to the groupBy clause.

Here is the working structure I use in my PowerShell scripts. Note that you must include talk, hold, or work in the metrics array, otherwise the groupBy has no data to bind to.

$payload = @{
 interval = "P7D"
 groupBy = @("wrapUpCode")
 metrics = @(
 @{ id = "talk" }
 @{ id = "work" }
 )
 entity = @{
 type = "agent"
 id = "<AGENT_ID>" 
 }
} | ConvertTo-Json -Depth 10

Invoke-RestMethod -Uri "https://api.mypurecloud.com/api/v2/analytics/details/agents" `
 -Method Post `
 -Headers $authHeader `
 -Body $payload
  • Ensure your OAuth token includes analytics:read scope.
  • Verify the wrapUpCode exists in the wrap-up code set referenced by the routing profile.
  • Check that the agents actually used that specific code in the selected time range.

If the code is still null, try adding status to the groupBy array temporarily. This often reveals if the issue is with the code itself or the aggregation logic. Also, make sure you are not filtering by a routing profile that doesn’t have the wrap-up code set attached. It’s a silent failure that catches everyone out.