Analytics API 413 on 90-day query

Just noticed that POST /api/v2/analytics/conversations/summary throws a 413 Entity Too Large when the date range covers 90 days. The payload is under 1MB, so it’s likely hitting a server-side query size limit. The generator doesn’t auto-split ranges. What’s the standard pattern for chunking this request in the SDK without breaking the aggregation logic?

split the 90-day window into smaller chunks, say 7 days each. the platform handles small windows way better than huge ranges. here’s a quick loop to handle it:

for start, end in chunk_dates(start_date, end_date, 7):
 resp = client.analytics.get_analytics_conversations_summary(start_date=start, end_date=end)
 aggregate(resp)

just make sure your aggregation logic sums up the totals correctly across chunks. don’t forget to handle any edge cases where the last chunk might be smaller.

The root cause here is the SDK not handling large date ranges gracefully. i’m coming from Terraform, so i usually chunk things manually.

try splitting the 90 days into 7-day blocks.

for start, end in chunk_dates(start_date, end_date, 7):
 client.analytics.postAnalyticsConversationsSummary(date_range=f"{start}/{end}")

it’s messy but works.

If I remember right, the 413 isn’t just about the date range size, it’s about the resulting payload volume hitting the gateway limit. The suggestions above to chunk by 7 days are fine for small orgs, but if you’re running this in a CI/CD pipeline for a large enterprise, you’ll likely hit rate limits or timeout issues with that granularity.

I usually decouple the query execution from the aggregation logic entirely. Instead of a simple loop, use a generator with exponential backoff for retries. The Python SDK (PureCloudPlatformClientV2) doesn’t handle cursor pagination automatically for summary endpoints, so you need to manage the after parameter manually if you’re dealing with high-volume data.

Here’s a more solid pattern I use in my automation scripts. It splits by 14 days (a sweet spot for performance vs. overhead) and handles the 429s gracefully:

from purecloudplatformclientv2 import AnalyticsApi, Configuration
from datetime import datetime, timedelta
import time

def query_summary_chunked(api, start, end, chunk_days=14):
 current_start = start
 results = []
 
 while current_start < end:
 current_end = min(current_start + timedelta(days=chunk_days), end)
 
 try:
 # Explicitly set the date range format
 response = api.post_analytics_conversations_summary(
 body={"dateRange": f"{current_start.isoformat()}/{current_end.isoformat()}"}
 )
 results.append(response)
 current_start = current_end
 except Exception as e:
 if "429" in str(e):
 wait_time = 2
 while wait_time <= 60:
 time.sleep(wait_time)
 wait_time *= 2
 try:
 response = api.post_analytics_conversations_summary(
 body={"dateRange": f"{current_start.isoformat()}/{current_end.isoformat()}"}
 )
 results.append(response)
 break
 except:
 continue
 else:
 raise e
 
 return aggregate_results(results)

Be careful with the aggregation step. If you’re summing up totalHandleTime or similar metrics, ensure you’re not double-counting overlaps. The API returns inclusive end dates, so your chunk boundaries need to be exclusive on the end side.

Also, check your OAuth scope. analytics:query:view is mandatory, but if you’re accessing detailed participant data within the summary, you might need analytics:details:view as well. Missing scopes often throw weird 403s that look like payload errors.

I’ve seen this fail silently in Terraform when the state file gets too large, so always write intermediate results to disk or a temp file. Don’t hold everything in memory if you’re querying 90 days of data for a large org.

Ah, this is a recognized issue…

The 413 error on /api/v2/analytics/conversations/summary isn’t just about the date range. It’s the resulting JSON payload size hitting the gateway limit before the backend even processes the aggregation. Chunking by 7 days is a band-aid. If you’re running this in a CI/CD pipeline or a large org, you’ll still hit rate limits or timeouts with that granularity.

I usually decouple the query execution from the aggregation logic entirely. Instead of a simple loop, use a generator with exponential backoff and smaller chunks. Here’s a Python snippet using the official SDK that handles this more gracefully:

import time
from PureCloudPlatformClientV2 import PureCloudAnalyticsApi

def get_chunked_analytics(api_instance, start_date, end_date, chunk_days=3):
 current_start = start_date
 while current_start < end_date:
 current_end = min(current_start + timedelta(days=chunk_days), end_date)
 try:
 response = api_instance.post_analytics_conversations_summary(
 start_date=current_start.strftime('%Y-%m-%d'),
 end_date=current_end.strftime('%Y-%m-%d'),
 body=your_request_body
 )
 yield response
 current_start = current_end + timedelta(days=1)
 except ApiException as e:
 if e.status == 429:
 time.sleep(2 ** retry_count)
 retry_count += 1
 else:
 raise

This approach keeps each payload small enough to bypass the 413 limit while respecting rate limits. You’ll need to handle the aggregation of the yielded responses manually, but it’s more reliable than hoping the SDK handles it for you.

Also, make sure your OAuth token doesn’t expire during long-running queries. Rotate it if needed.