Legacy Dev Forum Posts

 View Only

Sign Up

How to Parse or Flatten api/analytics/conversations/aggregate/query

  • 1.  How to Parse or Flatten api/analytics/conversations/aggregate/query

    Posted 06-05-2025 19:07

    Clayton_Ayers | 2023-02-07 19:53:44 UTC | #1

    I am trying to flatten out the response I get when running this api from VS code using Python. I am having a hard time importing it into a Pandas Dataframe and am not sure how to approach this. Currently I am only running this api with one QueueID, but in the future I will be exporting this data to a SQL table so that I can create a dashboard off of it and will need a more tabular view of all QueueIDs for a given date range. I am new to Python, has anyone else encountered this issue?

    Below is the Python I am running to pull data from the api:

    def conversationaggregatesgetintervalstring():

    Gets an ISO-8601 interval from now for the last x days

    now = datetime.now().replace(microsecond=0)

    week_ago = (now - timedelta(days=7)).replace(microsecond=0)

    return f"{ week_ago.isoformat() }/{ now.isoformat() }"

    print("----------------------------------------------------------------------------------")

    print("- Querying Que Historical Statistics for Conversation Aggregate Query - ")

    print("----------------------------------------------------------------------------------")

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient() \

    .getclientcredentialstoken(CLIENTID, CLIENT_SECRET)

    Genesys Cloud Objects

    routingapi = PureCloudPlatformClientV2.RoutingApi(apiclient)

    analyticsapi = PureCloudPlatformClientV2.AnalyticsApi(apiclient)

    Get "Support" queue by name

    try:

    queuedata = routingapi.getroutingqueues(name='TEST Service')

    except ApiException as e:

    print("Exception when calling RoutingApi->getroutingquest: {e}")

    sys.exit()

    print(f"queueData: {queue_data}")

    Store queue ID

    queueid = queuedata.entities[0].id

    Build analytics query

    query = PureCloudPlatformClientV2.ConversationAggregationQuery()

    query.interval = conversationaggregatesgetintervalstring()

    query.group_by = ['queueid']

    query.metrics = ['nOffered','nTransferred','tAcw','tConnected','tHeld','tWait','nTransferred','nOutbound']

    query.filter = PureCloudPlatformClientV2.ConversationAggregateQueryFilter()

    query.filter.type = 'and'

    query.filter.clauses = [PureCloudPlatformClientV2.ConversationAggregateQueryClause()]

    query.filter.clauses[0].type = 'or'

    query.filter.clauses[0].predicates = [PureCloudPlatformClientV2.ConversationAggregateQueryPredicate()]

    query.filter.clauses[0].predicates[0].dimension = 'queueId'

    query.filter.clauses[0].predicates[0].value = queue_id

    print(f"query: {query}")


    tim.smith | 2023-02-21 20:45:04 UTC | #2

    This blueprint may be of interest to you: https://developer.genesys.cloud/blueprints/conversation-model-to-sql-blueprint/


    system | 2023-03-23 20:45:48 UTC | #3

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


    This post was migrated from the old Developer Forum.

    ref: 18320