TypeError: 'StatisticalResponse' object is not subscriptable

Hi,
I have received the response from the API call post_analytics_users_aggregates_query().
The data is
[{'interval': '2022-05-10T00:00:00.000Z/2022-05-10T12:00:00.000Z',
'metrics': [{'metric': 'tAgentRoutingStatus',
'qualifier': 'INTERACTING',
'stats': 'sum': 17837647.0}},
{'metric': 'tAgentRoutingStatus',
'qualifier': 'NOT_RESPONDING',
'stats': { 'sum': 12600.0}},
{'metric': 'tAgentRoutingStatus',
'qualifier': 'IDLE',
'stats': { 'sum': 8063629.0 }}],
'views': None}]

I tried to perform the above data
df = pd.json_normalize(data, record_path = ["metrics"])

The Error responded is TypeError: 'StatisticalResponse' object is not subscriptable

However, when I assign the data in a variable and convert to a panda dataframe, it was completely fine.

Any guidance is appreciated. Thanks.

Hi Hnin,

Sorry for the delay here. Remember that when you use the Python SDK you are not getting the actual JSON object back from the SDK. Instead, you are getting a Python class back. You are getting a Python class. My suspicion is that a particular API call is trying to parse the JSON and referencing the value as if it were a subscribable variable. If you want to get a consumable map of maps you might want to use the utils.santize_for_serialization function call in the utils.py code in our SDK. This will a class and convert it to a dictionary of dictionaries representing the JSON object.

Hope that helps.

Thanks,
John Carnell
Manager, Developer Engagement

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.