Analytics API details query throwing 400 on agentEmail groupBy in Glue ETL

Problem

I am experiencing a persistent failure in our nightly AWS Glue ETL job responsible for extracting Genesys Cloud conversation analytics data and staging it for Redshift ingestion. The job targets the POST /api/v2/analytics/conversations/details/query endpoint to retrieve waitTime and agentEmail metrics. This pipeline has operated without issue for several months, but it has suddenly begun failing with a 400 error. The request payload validates successfully against our sandbox environment, yet the production API consistently rejects it. Consequently, the entire ETL pipeline stalls. I have implemented retry logic with exponential backoff to handle transient failures, but the 400 error persists across every retry attempt.

Environment Specifications:

  • Glue 4.0 with Python 3 and Spark 3.1
  • Genesys Cloud organization hosted on mypurecloud.com
  • Redshift cluster version 1.0.42083
  • Requesting waitTime and agentEmail in the groupBy array
  • S3 staging bucket located in eu-west-3
  • Redshift table schema expects agent_email varchar and wait_time bigint

The PySpark script dynamically constructs the JSON body by iterating through the target date range. Because the API call fails immediately, the S3 staging file remains empty, which prevents the downstream Redshift COPY command from executing. The Glue job terminates after the API rejection, leaving the PySpark DataFrame empty and causing our downstream dashboards to display stale data from the previous week. This incident disrupted our production queue for four hours yesterday, forcing a rollback to the prior day’s snapshot. Notably, the identical payload succeeds in the sandbox environment, suggesting a production-specific constraint such as a rate limit, OAuth permission scope mismatch, regional API behavior, or a schema drift on the Genesys Cloud side.

Code

{
 "dateFrom": "2023-10-01T00:00:00.000Z",
 "dateTo": "2023-10-02T00:00:00.000Z",
 "groupBy": ["agentEmail"],
 "metrics": ["waitTime"],
 "pageSize": 1000
}

Error

400 Bad Request
{
 "message": "Invalid groupBy field: agentEmail is not supported for this metric combination.",
 "code": "invalid_request"
}

Question

Given that the documentation indicates agentEmail should be compatible with waitTime, I am investigating several potential root causes. Could the Europe/Paris timezone configuration be interfering with the API’s date bucketing logic? Is it possible that cursor pagination is silently dropping the agentEmail field on subsequent pages, causing the initial request to fail validation? Alternatively, could this be related to the OAuth token scopes (analytics:reports:read and analytics:exports:read), a production-specific rate limit, or a recent schema drift on the Genesys Cloud analytics API? I would appreciate any insights into why the production environment rejects this valid payload while the sandbox accepts it, and how to adjust the request or job configuration to restore the pipeline.