Make sure you audit the select array before worrying about the date chunking strategy. The suggestion above about trimming fields is correct, but there is a specific gotcha in the PHP SDK that often catches people out when they try to optimize these queries.
Cause: The 413 error is triggered by the total byte size of the JSON payload sent to /api/v2/analytics/conversations/summaries. When you request a 90-day window, you might assume the issue is the time range, but it is usually the cardinality of the groupBy combined with a verbose select list. If you include metrics like agent.talk, hold, work, and wrapup alongside a high-cardinality groupBy like skill or queue, the resulting JSON object can easily exceed the 1MB limit for a single POST request, even if the date range is only 7 days.
Solution: In my Laravel projects, I use Guzzle to manually construct the request body to ensure strict size control. You must strip the select array down to only the metrics you absolutely need. Here is a snippet showing how I prepare the payload before sending it via the SDK’s underlying HTTP client to bypass any SDK-level serialization bloat:
// Define minimal select to keep payload small
$select = ['queue.name', 'agent.talk', 'hold'];
$body = [
'dateFrom' => '2023-10-01T00:00:00.000Z',
'dateTo' => '2023-10-08T00:00:00.000Z',
'interval' => 'P7D',
'select' => $select,
'groupBy' => ['queue'], // Avoid high-cardinality groupBy if possible
'filter' => ['metric' => 'talk', 'operator' => '>', 'value' => 0]
];
// Serialize and check size before sending
$jsonBody = json_encode($body);
if (strlen($jsonBody) > 500000) {
// Fallback: further reduce select or split groupBy
}
$response = $analyticsApi->postAnalyticsConversationsSummaries(
$jsonBody,
null,
null,
null,
null,
null,
null,
null,
null,
null
);
By keeping the select array tight and verifying the JSON string length before the request, you can reliably fetch 7-day chunks without hitting the 413 limit.