CXone Reporting API (v2) Agent State History Query Logic

We are attempting to retrieve the agent state history for the last 24 hours using the CXone Reporting API (v2). The goal is to map these state changes to our internal Terraform state for drift detection in workforce configurations.

We have constructed an OData query targeting the /api/v2/reporting/agentstates endpoint. The request includes the necessary $filter parameters for the time range and specific user IDs. Here is the current request structure:

GET /api/v2/reporting/agentstates?$filter=timestamp ge 2023-10-27T10:00:00Z and timestamp lt 2023-10-28T10:00:00Z and userId eq '12345678-1234-1234-1234-123456789012'

The response returns a 200 OK status, but the payload structure is not aligning with our expectations for a continuous timeline. The data appears fragmented, with gaps in the state transitions that do not correspond to any documented ‘off-phone’ or ‘auxiliary’ codes. We suspect the OData query might be missing a required dimension or that the aggregation level is too coarse.

We have verified the OAuth token is valid and has the reporting:agentstates:view scope. The issue persists across multiple agents. We are unsure if we need to use the /api/v2/reporting/agentstates/summary endpoint instead, or if there is a specific $expand parameter required to flatten the state history into a usable JSON array for our Python processing script.

Any insights into the correct OData syntax for retrieving a continuous state history would be appreciated. We are currently parsing the raw JSON and encountering null values for the stateName field in approximately 30% of the records, which breaks our downstream logic.