ServiceNow integration failing with 500 Internal Server Error on Analytics Conversation Summary endpoint

How do I correctly to handle pagination and date range filtering when querying the Genesys Cloud Analytics API via a ServiceNow Scripted REST API?

We have a ServiceNow MID Server configured to pull conversation summary data from Genesys Cloud for daily reporting. The integration uses the POST /api/v2/analytics/conversations/summary endpoint. The ServiceNow script constructs a JSON payload with specific segment filters and a date range. The date range is calculated based on the London timezone (Europe/London), ensuring the from and to timestamps are in UTC format as required by the API documentation.

The request is failing with a 500 Internal Server Error. The response body contains a generic error message: {"code":"server_error","message":"An unexpected error occurred."}. This is frustrating because the same payload, when tested using Postman with a valid OAuth token, returns the expected data without issues.

The ServiceNow script uses the RESTMessageV2 class to send the request. The headers include Authorization: Bearer <token>, Content-Type: application/json, and Accept: application/json. The token is refreshed every hour using the client credentials flow. The MID Server logs show the request is sent correctly, and the response is received, but the parsing fails due to the 500 status.

The JSON payload structure is as follows:

{
 "group_by": "wrap_up_code",
 "filter": {
 "and": [
 {
 "field": "conversation.type",
 "op": "eq",
 "value": "voice"
 },
 {
 "field": "conversation.status",
 "op": "eq",
 "value": "complete"
 }
 ]
 },
 "from": "2023-10-01T00:00:00.000Z",
 "to": "2023-10-01T23:59:59.999Z"
}

Has anyone encountered a similar issue where the Analytics API returns a 500 error for valid requests from an external system like ServiceNow? Could there be a rate limiting or IP whitelisting issue that is not clearly documented in the Genesys Docs? We have verified that the MID Server IP is allowed in the Genesys Cloud tenant settings. Any insights into debugging this 500 error would be appreciated.