Trying to fetch call detail records for the last 90 days using the analytics/conversations/summary endpoint. The request body payload keeps hitting the 413 Entity Too Large limit, even though the date range seems standard. How do I split this into smaller chunks without missing data at the boundaries?
90 days in a single analytics/conversations/summary call is a recipe for disaster. The payload isn’t just large; it’s likely triggering internal aggregation timeouts before it even hits your client. You’re seeing 413, but the real issue is the sheer volume of data you’re asking the platform to process in one go.
Don’t try to chunk by arbitrary dates. That’s where you’ll miss data at the boundaries, especially with timezone shifts or overlapping intervals. Instead, use the groupBy parameter effectively and iterate through date ranges programmatically. Break that 90-day window into 7-day chunks. It’s cleaner, safer, and much easier to retry if one slice fails.
Here’s how you’d structure the loop in Node.js using the PureCloud SDK:
const platformClient = require('genesyscloud-purecloud-platform-client-v2');
const analyticsApi = new platformClient.AnalyticsApi();
const startDate = '2023-10-01T00:00:00.000Z';
const endDate = '2023-12-30T00:00:00.000Z';
const chunkSize = 7; // days
async function fetchChunks() {
let currentStart = new Date(startDate);
const end = new Date(endDate);
while (currentStart < end) {
const nextStart = new Date(currentStart);
nextStart.setDate(currentStart.getDate() + chunkSize);
// Ensure we don't overshoot the final end date
const chunkEnd = nextStart > end ? end : nextStart;
const body = {
dateFrom: currentStart.toISOString(),
dateTo: chunkEnd.toISOString(),
groupBy: ['conversation.media.type'],
pageSize: 500
};
try {
const result = await analyticsApi.postAnalyticsConversationsSummary(body);
console.log(`Processed chunk: ${currentStart.toISOString()} to ${chunkEnd.toISOString()}`);
// Store or process result.data
} catch (err) {
console.error(`Failed chunk starting at ${currentStart.toISOString()}:`, err);
}
currentStart = nextStart;
}
}
Keep an eye on the dateTo field. It’s exclusive, so make sure your next dateFrom matches exactly where the previous dateTo left off. If you’re still hitting limits after chunking, check if your groupBy fields are creating too many unique combinations. Simplify the grouping if needed.