Somik_Mukherjee1 | 2022-07-08 16:36:12 UTC | #1
I am using Conversation aggregates query to pull conversation IDs. The query is executed successfully and gives me response. However, I am only able to print the entire response. I am unable to access only the conversation ID field:
apiresponse: PureCloudPlatformClientV2.ConversationAggregationQuery = apiinstance.postanalyticsconversationsaggregatesquery(query) items: PureCloudPlatformClientV2.Conversation responselist = apiresponse pprint(responselist) sourceFile.write(str(apiresponse))
Sample response:
{'results': [{'data': [{'interval': '2021-12-31T18:30:00.000Z/2022-01-01T18:30:00.000Z',
'metrics': [{'metric': 'nConnected',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}},
{'metric': 'nOffered',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}}],
'views': None}],
'group': {'conversationId': '00212cfb-eb97-4dc9-ae98-2e88aab9d2de',
'mediaType': 'email'}},
{'data': [{'interval': '2021-12-31T18:30:00.000Z/2022-01-01T18:30:00.000Z',
'metrics': [{'metric': 'nConnected',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}},
{'metric': 'nOffered',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}}],
'views': None}],
'group': {'conversationId': '0024b87f-657e-4ea2-bbfb-1c58865133e7',
'mediaType': 'email'}},
{'data': [{'interval': '2021-12-31T18:30:00.000Z/2022-01-01T18:30:00.000Z',
'metrics': [{'metric': 'nConnected',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}},
{'metric': 'nOffered',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}}],
'views': None}],
'group': {'conversationId': '002a9320-1edb-4c21-a637-e73eea305ace',
'mediaType': 'email'}},
{'data': [{'interval': '2021-12-31T18:30:00.000Z/2022-01-01T18:30:00.000Z',
'metrics': [{'metric': 'nConnected',
'qualifier': None,
'stats': {'count': 2,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}},
{'metric': 'nOffered',
'qualifier': None,
'stats': {'count': 1,
'count_negative': None,
'count_positive': None,
'current': None,
'denominator': None,
'max': None,
'min': None,
'numerator': None,
'ratio': None,
'sum': None,
'target': None}}],
'views': None}]
anon14299330 | 2022-07-11 15:52:38 UTC | #2
Hi,
I tried this out as an example and I am able to access all properties from the api response. Please double check your python syntax for accessing items in a list of objects. I believe you are trying to access the conversationId from the group object in the api_response. I am not an experienced python programmer but something like this may work for your use case:
for item in api_response.results:
pprint(item.group["conversationId"])
Thanks,
Mike
Somik_Mukherjee1 | 2022-07-11 17:49:13 UTC | #3
Hi Mike,
Thanks a lot for your response. It gives a "Key-error" when using your syntax, tried changing the conversation_id exactly how it is returned from the object:
Thanks, Somik Mukherjee
anon14299330 | 2022-07-14 13:21:24 UTC | #4
Hi,
The reason why you are getting a key error is because the key conversation_id does not exist. The correct key is conversationId as seen in the code example I gave above.
Thanks,
Mike
Somik_Mukherjee1 | 2022-07-14 15:10:21 UTC | #5
I tried the same as well the other day but it also came up with key error:
[Uploading: Screenshot 2022-07-14 203952.png...]()
anon14299330 | 2022-07-14 15:35:46 UTC | #6
Hi,
can you upload a formatted example of your API response please?
Thanks,
Mike
Somik_Mukherjee1 | 2022-07-14 16:17:02 UTC | #7
Hi Mike,
Here is the response: Created a channel {'entities': [{'id': 'v2.routing.queues.26b2c827-93b4-490e-b58d-0ba9206e828d.conversations', 'selfuri': None}]} C:\git\genesys-cloud\python-scripts\scriptssomik\automatictranferinteractions\autotransferinteraction.py:121: DeprecationWarning: There is no current event loop groupedasync = asyncio.gather(listentoWebsocket()) C:\git\genesys-cloud\python-scripts\scriptssomik\automatictranferinteractions\autotransferinteraction.py:122: DeprecationWarning: There is no current event loop asyncio.geteventloop().rununtilcomplete(groupedasync) Listening to websocket Display analytics observation query. Traceback (most recent call last): File "C:\git\genesys-cloud\python-scripts\scriptssomik\automatictranferinteractions\autotransferinteraction.py", line 122, in <module> asyncio.geteventloop().rununtilcomplete(groupedasync) File "C:\Users\somik.mukherjee\AppData\Local\Programs\Python\Python310\lib\asyncio\baseevents.py", line 646, in rununtilcomplete return future.result() File "C:\git\genesys-cloud\python-scripts\scriptssomik\automatictranferinteractions\autotransferinteraction.py", line 110, in listentoWebsocket displayqueueobservation() File "C:\git\genesys-cloud\python-scripts\scriptssomik\automatictranferinteractions\autotransferinteraction.py", line 95, in displayqueueobservation pprint(item.group["conversationId"]) KeyError: 'conversationId'
Thanks, Somik
anon14299330 | 2022-07-15 16:34:46 UTC | #8
Hi,
I'm not sure why the above code example is not working for you so I am going to post my full example code below which has been tried and tested to work correctly. I suggest that you run this example code separately from your main application to see how it works first, this way you may be able to pin point the syntax errors or where you are going wrong in your main application.
import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint
PureCloudPlatformClientV2.configuration.access_token = 'your_access_token_goes_here'
api_instance = PureCloudPlatformClientV2.ConversationsApi()
body = {
"interval": "your_interval_goes_here",
"groupBy": [
"conversationId"
],
"metrics": [
"nConnected"
],
}
try:
api_response = api_instance.post_analytics_conversations_aggregates_query(body)
for item in api_response.results:
pprint(item.group["conversationId"])
except ApiException as e:
print("Exception when calling PostAnalyticsConversationsAggregatesQueryRequest->post_analytics_conversations_aggregates_query: %s\n" % e)
Thanks,
Mike
Somik_Mukherjee1 | 2022-07-15 17:03:09 UTC | #9
Hi Mike,
I am using queue observation query and not conversation detail or aggregate query. Below is my body:
query = PureCloudPlatformClientV2.QueueObservationQuery() # QueueObservationQuery | query
query = {
"filter": {
"type": "AND",
"clauses": [
{
"type": "AND",
"predicates":[
{
"dimension" : "queueId",
"value": QUEUE_ID
},
{
"dimension": "mediaType",
"value": "email"
}
]
}
]
},
"detailMetrics": ["oWaiting"],
"metrics":["oWaiting"]
} try:
Query for queue observations
apiresponse = apiinstance.postanalyticsqueuesobservationsquery(query)
print("Display analytics observation query.")
pprint(api_response.results)
for item in api_response:
pprint(item.group["conversationId"])
sourceFile.write(str(item.group["conversationId"]))
sourceFile.close()
except ApiException as e:
print ("Exception when calling AnalyticsApi->postanalyticsqueuesobservationsquery: %s\n" % e)
system | 2022-08-15 17:03:14 UTC | #10
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 15450