Hitting a wall with the Analytics API. Trying to pull queue metrics for the last 90 days. The payload size is too big and the server is rejecting it with 413 Entity Too Large.
Here’s the request body I’m sending via the Node SDK:
await analyticsApi.queueApi.queueMetricsGet({
queueId: 'my-queue-id',
interval: 'P1D',
rangeStart: '2023-10-01T00:00:00Z',
rangeEnd: '2023-12-30T00:00:00Z',
groupBy: 'interval'
});
The SDK doesn’t seem to have a built-in chunking mechanism for this endpoint. I’ve tried narrowing the window to 30 days and it works fine. Is there a recommended way to split this into multiple requests and merge the results client-side? Or am I missing a parameter that handles pagination for large date ranges? The docs don’t mention a max date span.
The 413 error hits because you’re asking for 90 days of daily intervals in one shot. The response payload swells past the server limit before it even gets back to you. You need to chunk the request.
Don’t try to fetch it all at once. Split the date range into smaller blocks, like 14 or 30 days. Loop through the chunks, aggregate the data locally, then move to the next block. Here’s a quick pattern in Node:
const chunks = [];
let start = new Date('2023-10-01T00:00:00Z');
const end = new Date('2023-12-30T00:00:00Z');
const chunkSizeDays = 14;
while (start < end) {
const chunkEnd = new Date(start);
chunkEnd.setDate(start.getDate() + chunkSizeDays);
if (chunkEnd > end) chunkEnd.setTime(end.getTime());
chunks.push({ start: start.toISOString(), end: chunkEnd.toISOString() });
start.setTime(chunkEnd.getTime());
}
// Iterate chunks and call analyticsApi.queueApi.queueMetricsGet for each
Keep an eye on rate limits too. Adding a small delay between requests prevents 429s. The API is strict on payload size.