Legacy Dev Forum Posts

 View Only

Sign Up

Example query similar to a join or union in SQL

  • 1.  Example query similar to a join or union in SQL

    Posted 06-05-2025 18:18

    James.Riley | 2021-02-23 23:14:12 UTC | #1

    I have a need to provide a means (API query) to get a count of times a specific scenario occurs. When I look at the data in various API’s, all the data is technically present for me to get, however I am needing an example query that crosses API’s.

    For instance, via the *Analytics Conversation Detail query* , I can return a list of or count of ConversationIDs based on a search on the sipResponseCodes for a specific SIP code (480 as an example), but I do not have the ability to see the resultant "phrase": "WebRTC disconnect" attached to that sipResponseCode in the Analytics data. The phrase is available via the *Get Conversation query* of the same ConversationID. As a result, I am needing an example API query of what I would typically do in SQL as a union/join of the two data sets in a single query.

    I am currently utilizing Python as my coding language for accessing the Analytics, and Conversations API. I progressed to the point where I believed I had a viable query to return the specific scenario, but the query never returned the exact CallID of the example I was using to build the criteria for the query.


    James.Riley | 2021-03-06 04:40:18 UTC | #2

    Before this post closes automatically with no response... Here are my learnings in the last 10 days, (novice API and novice Python user) while working through my scenario using the python SDK...

    First use these for sure... import json import requests import datetime

    After you come up with your API call and body "PullQuery" in my example, define a callback function to iterate through the JSON response to your query.

    queryresult = api.postanalyticsconversationsdetailsquery(PullQuery, callback=callbackfunction)

    Here is a small piece of my code iterating through the response and the equivalent of a Data Action's Translation Map...

    def callbackfunction(response): setLoop = -1 for index,value in enumerate(response.tojson()): maxLoop = (response.conversations.len()) setLoop += 1 partLoop = -1 if setLoop < maxLoop : convID = response.conversations[setLoop].conversationid urlPath = "https://apps.mypurecloud.com/directory/#/engage/admin/interactions/" + str(convID) partCount = (response.conversations[setLoop].participants._len_()) partLoop += 1 print("* ConversationID * : " + response.conversations[setLoop].conversationid )

    Hope this helps someone else who is a newbie to either the API, Python SDK or both...


    Becky_Powell | 2021-03-08 16:19:20 UTC | #3

    Hello James! First of all, please accept my deepest apologies that we somehow missed your forum post on the 23rd of February. Our goal is to respond to each and every post in a timely manner. We've clearly missed our mark here.

    I will escalate this question among our Developer Engagement team and will ensure that someone answers you by the end of the business day.


    tim.smith | 2021-03-08 16:38:14 UTC | #4

    James.Riley, post:1, topic:10069
    I have a need to provide a means (API query) to get a count of times a specific scenario occurs. When I look at the data in various API’s, all the data is technically present for me to get, however I am needing an example query that crosses API’s.

    Analytics queries come in two main varieties, detail and aggregate. The detail queries return the full conversation object for all conversations matching the query. Aggregate queries provide metric data about the conversations that match the queries. If you can construct a filter that precisely matches the specific scenario you're looking for, using an aggregate query to get a count should work. But if you're looking for something that you can't filter for directly, you'll need to get as close as you can with a detail query and then post-process the results to apply the additional logic necessary to count the things you want to count.

    Here are some resources that you may find useful:


    system | 2021-04-08 16:38:15 UTC | #5

    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: 10069