Queues and Agents Analytics API (Observation & Aggregation)

We are trying to get the data shown on the Performance->Queues screen and the Performance->Agents screen using Platform API but many of the requested metrics are not being returned(even when we see some data in those Metrics on these screens)

In order to get the Performance->Queues screen data we are using the API observation method: "/api/v2/analytics/queues/observations/query" but when we get the response back most of the metrics don't come back, and the ones that comes back are mostly null or 0s.

Code used to get the Queues data:

// Get all Queues 
var queueApi = new RoutingApi(); 
QueueEntityListing allQueues = queueApi.GetQueues(); 


//Set Objects to call Queue Observation Method 
var analyticsApi = new AnalyticsApi(); 

List<AnalyticsQueryPredicate> predicates = new List<AnalyticsQueryPredicate>(); 
List<AnalyticsQueryClause> clauses = new List<AnalyticsQueryClause>(); 

AnalyticsQueryFilter xx = new AnalyticsQueryFilter(AnalyticsQueryFilter.TypeEnum.Or); 

ObservationQuery body = new ObservationQuery(xx); 

List<QueueCR> gridQueues = new List<QueueCR>(); 

foreach (Queue q in allQueues.Entities) 
{ 
AnalyticsQueryPredicate predicate = new AnalyticsQueryPredicate(); 
predicate.Dimension = AnalyticsQueryPredicate.DimensionEnum.Queueid; 
predicate.Value = q.Id; 
predicates.Add(predicate); 

QueueCR queueCr = new QueueCR(); 
queueCr.queueId = q.Id; 
queueCr.name = q.Name; 
gridQueues.Add(queueCr); 
} 

body.Filter.Clauses = clauses; 
body.Filter.Predicates = predicates; 

List<ObservationQuery.MetricsEnum> list = new List<ObservationQuery.MetricsEnum>(); 
list.Add(ObservationQuery.MetricsEnum.Oservicelevel); 
list.Add(ObservationQuery.MetricsEnum.Tabandon); 
list.Add(ObservationQuery.MetricsEnum.Owaiting); 
list.Add(ObservationQuery.MetricsEnum.Ointeracting); 
list.Add(ObservationQuery.MetricsEnum.Oactiveusers); 
list.Add(ObservationQuery.MetricsEnum.Ttalk); 
list.Add(ObservationQuery.MetricsEnum.Tacw); 
list.Add(ObservationQuery.MetricsEnum.Theld); 
body.Metrics = list; 

QualifierMappingObservationQueryResponse res = analyticsApi.PostQueuesObservationsQuery(body); 

In order to get the Performance->Agents screen data we are using the API aggregation method: "/api/v2/analytics/users/aggregates/query" but when we get the response back most of the metrics don't come back, and the ones that comes back are mostly null or 0s.

Code used to get the Agents data:

On this one, I'm passing a interval parameter, I tested with intervals that have active users making calls but I got the same results.

List<AnalyticsQueryPredicate> userPredicates = new List<AnalyticsQueryPredicate>(); 
List<AnalyticsQueryClause> userClauses = new List<AnalyticsQueryClause>(); 

foreach (User q in allUsers.Entities) 
{ 
AnalyticsQueryPredicate userPredicate = new AnalyticsQueryPredicate(); 
userPredicate.Dimension = AnalyticsQueryPredicate.DimensionEnum.Userid; 
userPredicate.Value = q.Id; 
userPredicates.Add(userPredicate); 

UserCR userCr = new UserCR(); 
userCr.userId = q.Id; 
userCr.name = q.Name; 
gridUsers.Add(userCr); 
} 

AnalyticsQueryFilter userFilter = new AnalyticsQueryFilter(AnalyticsQueryFilter.TypeEnum.Or); 

AggregationQuery userBody = new AggregationQuery(); 
userBody.Interval = "2017-01-21T16:00:00.000Z/2017-01-21T16:30:00.000Z"; 
List<AggregationQuery.GroupByEnum> alist = new List<AggregationQuery.GroupByEnum>(); 
alist.Add(AggregationQuery.GroupByEnum.Userid); 
userBody.GroupBy = alist; 
userBody.Filter = userFilter; 

userBody.Filter.Clauses = userClauses; 
userBody.Filter.Predicates = userPredicates; 

List<AggregationQuery.MetricsEnum> ulist = new List<AggregationQuery.MetricsEnum>(); 
ulist.Add(AggregationQuery.MetricsEnum.Ntransferred); 
ulist.Add(AggregationQuery.MetricsEnum.Tacw); 
ulist.Add(AggregationQuery.MetricsEnum.Tagentroutingstatus); 
ulist.Add(AggregationQuery.MetricsEnum.Tanswered); 
ulist.Add(AggregationQuery.MetricsEnum.Thandle); 
ulist.Add(AggregationQuery.MetricsEnum.Ttalk); 
ulist.Add(AggregationQuery.MetricsEnum.Torganizationpresence); 
ulist.Add(AggregationQuery.MetricsEnum.Theld); 
ulist.Add(AggregationQuery.MetricsEnum.Tsystempresence); 
userBody.Metrics = ulist; 

PresenceQueryResponse userRes = analyticsApi.PostUsersAggregatesQuery(userBody);

Please notice how we request several metrics in both Queue and Users but we don't get of these metrics back(a few only and I'm not sure about the accuracy of its value).

Thanks.

You only get metrics back that have values for the interval. For example, if you request queue observation data for an interval and there were no conversations that touched the queue during that interval, you probably won't get any data back.

It's also important to understand that a value of 0 is different from the metric not being returned. A value of 0 indicates that there is data, and it's exactly 0. No metric means that no data has been generated at all, so it's not 0, it's null.

Hi Tim,

Thanks for your quick response.
To retrieve Performance->Queues screen data I'm using the Observation method for Queue.

The Observation method for Queues do not accept Interval parameter value. It's always returning the same 2 or 3 metrics everytime, Can we get the Data we want with the Observation Method?

On the Agents screen is where I'm passing the Interval Parameter(using the Aggregation method).
However, I have performed some tests, using the same interval showed on the Performance->Agents screen.
But unfortunately when I review the PresenceQueryResponse.Results (returned data.)

All agents only have 1 or 2 metrics (the same 2 metrics always). But at the same time(interval) when I check Performance->Agents screen I can see some data in some of the Metrics there( this data is not being returned on the PresenceQueryResponse.Results)

See image below:

Regards!

You'll need to use a combination of analytics resources to assemble data like you're seeing in the queue or agent dashboards. There are articles discussing the analytics resources linked on the right sidebar on the Analytics API documentation page. Here's a few tips that may be helpful in finding the data you need:

  • Observation queries only provide instant observations about the resource. Any data that is measured over any period of time cannot come from observations resources.
  • Aggregate queries will probably provide most of the data you're looking for. Aggregate data is an accumulation of data over an interval.
  • Detail queries will provide non-summarized data per entity.

If you can't find a specific metric, let me know.

Hi Tim,

Thanks very much for your tips and explanation.
I reviewed analytics resources and I was able to get most of the metrics needed using the Conversations aggregation query. "/api/v2/analytics/conversations/aggregates/query"
I'm asking for all available metrics for the UserIDs that I pass to the API Method, and for this Interval and Granularity:
ubody.Interval = "2017-02-01T013:00:00/2017-02-02T14:00:00";
ubody.Granularity = "PT30M";

(Please notice that I'm using Interval from Feb 1st to Feb 2nd)
And now I can see metrics and data coming back. But the Data coming back shows some Intervals for times that still hasn't happened yet. (16:00, 16:30,17:00) when it is right now about 14:30.

On those screens (Performance->Agents, Queues), the interval are always for the current Half hour, so when I try to make the same request, just changing the interval to the current Interval( or actually any interval within the same day - Feb 1st, today),
I get not results, AggregateQueryResponse.Results is Null. For this Interval:

ubody.Interval = "2017-02-01T13:00:00/2017-02-01T14:00:00";
ubody.Granularity = "PT30M";

What do you recommend to avoid this or fix this behavior?

Thanks for your help and Best Regards.

I'm not sure how you're getting future intervals back. Can you currently reproduce? I'd like to see the full query (call .ToJson() on the request body object) and the context ID from the response (use PostConversationsAggregatesQueryWithHttpInfo() and get it from the headers property on the response).

Hi Tim,

Yes, I'm able to reproduce it. I just tried with this interval(before 4pm today):

ubody.Interval = "2017-02-02T14:00:00/2017-02-03T16:00:00";
ubody.Granularity = "PT30M";

I also attached the Headers for the response with (PostConversationsAggregatesQueryWithHttpInfo()).

I have added the full query(.ToJson()). (It was too long I could not formatted)

{
  "results": [
    {
      "group": {
        "mediaType": "voice",
        "userId": "9442954f-d74e-4fff-8147-eb9ad7b38fb2"
      },
      "data": [
        {
          "interval": "2017-02-02T14:00:00.000Z/2017-02-02T14:30:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 304538,
                "min": 183577,
                "count": 2,
                "sum": 488115
              }
            },
            {
              "metric": "Tacd",
              "stats": {
                "max": 8652,
                "min": 8652,
                "count": 1,
                "sum": 8652
              }
            },
            {
              "metric": "Tacw",
              "stats": {
                "max": 120000,
                "min": 120000,
                "count": 2,
                "sum": 240000
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 184538,
                "min": 63577,
                "count": 2,
                "sum": 248115
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 184538,
                "min": 63577,
                "count": 2,
                "sum": 248115
              }
            },
            {
              "metric": "Tanswered",
              "stats": {
                "max": 8652,
                "min": 8652,
                "count": 1,
                "sum": 8652
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T14:30:00.000Z/2017-02-02T15:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 190815,
                "min": 190815,
                "count": 1,
                "sum": 190815
              }
            },
            {
              "metric": "Tacd",
              "stats": {
                "max": 10771,
                "min": 10771,
                "count": 1,
                "sum": 10771
              }
            },
            {
              "metric": "Tacw",
              "stats": {
                "max": 120000,
                "min": 120000,
                "count": 1,
                "sum": 120000
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 70815,
                "min": 70815,
                "count": 1,
                "sum": 70815
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 70815,
                "min": 70815,
                "count": 1,
                "sum": 70815
              }
            },
            {
              "metric": "Tanswered",
              "stats": {
                "max": 10731,
                "min": 10731,
                "count": 1,
                "sum": 10731
              }
            }
          ]
        }
      ]
    },
    {
      "group": {
        "mediaType": "voice",
        "userId": "a3cf4c64-6f18-4200-b1bc-94ad9fd9a645"
      },
      "data": [
        {
          "interval": "2017-02-02T14:00:00.000Z/2017-02-02T14:30:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 33744,
                "min": 18882,
                "count": 3,
                "sum": 77111
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 33744,
                "min": 18882,
                "count": 3,
                "sum": 77111
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T14:30:00.000Z/2017-02-02T15:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 22373,
                "min": 2120,
                "count": 3,
                "sum": 35810
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 22373,
                "min": 2120,
                "count": 3,
                "sum": 35810
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T15:30:00.000Z/2017-02-02T16:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 2458228,
                "min": 2458228,
                "count": 1,
                "sum": 2458228
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 2458228,
                "min": 2458228,
                "count": 1,
                "sum": 2458228
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 2458228,
                "min": 2458228,
                "count": 1,
                "sum": 2458228
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T16:00:00.000Z/2017-02-02T16:30:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 95827,
                "min": 12670,
                "count": 8,
                "sum": 371094
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 95827,
                "min": 12670,
                "count": 8,
                "sum": 371094
              }
            },
            {
              "metric": "Nerror",
              "stats": {
                "count": 2
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 95827,
                "min": 12670,
                "count": 8,
                "sum": 371094
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T16:30:00.000Z/2017-02-02T17:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 187668,
                "min": 13072,
                "count": 6,
                "sum": 442579
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 187668,
                "min": 13072,
                "count": 6,
                "sum": 442579
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 187668,
                "min": 13072,
                "count": 4,
                "sum": 353089
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T17:00:00.000Z/2017-02-02T17:30:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 41886,
                "min": 16129,
                "count": 5,
                "sum": 134500
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 41886,
                "min": 16129,
                "count": 5,
                "sum": 134500
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 41886,
                "min": 16129,
                "count": 5,
                "sum": 134500
              }
            }
          ]
        },
        {
          "interval": "2017-02-02T17:30:00.000Z/2017-02-02T18:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 115985,
                "min": 67082,
                "count": 2,
                "sum": 183067
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 115985,
                "min": 67082,
                "count": 2,
                "sum": 183067
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 115985,
                "min": 67082,
                "count": 2,
                "sum": 183067
              }
            }
          ]
        }
      ]
    },
    {
      "group": {
        "mediaType": "voice",
        "userId": "74ad04de-2048-4e52-86a8-c2db857e933e"
      },
      "data": [
        {
          "interval": "2017-02-02T20:30:00.000Z/2017-02-02T21:00:00.000Z",
          "metrics": [
            {
              "metric": "Thandle",
              "stats": {
                "max": 343089,
                "min": 156727,
                "count": 2,
                "sum": 499816
              }
            },
            {
              "metric": "Tacd",
              "stats": {
                "max": 17071,
                "min": 8824,
                "count": 2,
                "sum": 25895
              }
            },
            {
              "metric": "Tacw",
              "stats": {
                "max": 120000,
                "min": 120000,
                "count": 2,
                "sum": 240000
              }
            },
            {
              "metric": "Ttalkcomplete",
              "stats": {
                "max": 223089,
                "min": 36727,
                "count": 2,
                "sum": 259816
              }
            },
            {
              "metric": "Ttalk",
              "stats": {
                "max": 223089,
                "min": 36727,
                "count": 2,
                "sum": 259816
              }
            },
            {
              "metric": "Tanswered",
              "stats": {
                "max": 17030,
                "min": 8823,
                "count": 2,
                "sum": 25853
              }
            }
          ]
        }
      ]
    }
  ]
}

Thanks very much. Regards.

I don't see an issue with that result set. The latest interval is 2017-02-02T20:30:00.000Z/2017-02-02T21:00:00.000Z, which is 3:30-4 EST today.

Hi Tim,

Thanks very much for your help! I was not using the right timezone.
I was able to get all data from those screen using a combination of Aggregation, Observation and Details queries. My only doubt now is the Time in Status field for agents it's returning the value only for the interval but on those screen the time in status can include several intervals, I will try to do some test with different calls, but if you have any tips on retrieving this field, I'd appreciate it.

Thanks again for your tips and explanations.

Best Regards!