Get Agents On Queue using /api/v2/analytics/queues/observations/query

Following the deprecation of the API "/api/v2/routing/queues/${queueId}/users?joined=true&presence=ON%20QUEUE" I would like to use the following API "/api/v2/analytics/queues/observations/query" to get a count of how many agents are IDLE on queue.

I've used the Query Builder to return the data I want.

Query

{
 "filter": {
  "type": "or",
  "predicates": [
   {
    "type": "dimension",
    "dimension": "queueId",
    "operator": "matches",
    "value": "6bbb592d-175f-4502-95dc-43db6c2039c1"
   }
  ]
 },
 "metrics": [
  "oUserRoutingStatuses"
 ]
}

Query Results

{
  "results": [
    {
      "group": {
        "queueId": "6bbb592d-175f-4502-95dc-43db6c2039c1"
      },
      "data": [
        {
          "metric": "oUserRoutingStatuses",
          "qualifier": "INTERACTING",
          "stats": {
            "count": 1
          }
        },
        {
          "metric": "oUserRoutingStatuses",
          "qualifier": "IDLE",
          "stats": {
            "count": 1
          }
        },
        {
          "metric": "oUserRoutingStatuses",
          "qualifier": "OFF_QUEUE",
          "stats": {
            "count": 4
          }
        }
      ]
    }
  ]
}

Using this information I built a data action with the appropriate configuration and contracts. Please see attached.
Get-Queue-Agents-20210902152736.custom.json (2.2 KB)

Running a test from the data action I get a flattened output for the metrics, qualifiers showing the correct information however for the counts it shows no data. Is this because a list of integers can't be flattered?

If I look at the JSON I see the counts are there.

I tried to use this data action in an Inbound Flow however upon entering the data action it fails straight away.

Am I going about this the right way? I know I could potentially translation map the data to specific contacts but I don't exactly how many results will be returned in the data array each time. Any help would be appreciated?

Thanks,
Darren

1 Like

Hello,

If you are planning to use the observation query on a single queue and if you are only interested in IDLE count, you could do the following to automatically extract a single value.

You can modify your Output Contract to:

{
  "type": "object",
  "properties": {
    "idleCount": {
      "type": "integer"
    }
  },
  "additionalProperties": true
}

If you have already published your Data Action once, you'll need to create a new one as contracts can't be modified once the data action has been published.

Then, in your Response Configuration, you can use the following:

{
  "translationMap": {
    "idleCountArray": "$.results[0].data[?(@.qualifier == 'IDLE')].stats.count"
  },
  "translationMapDefaults": {},
  "successTemplate": "{\"idleCount\": ${successTemplateUtils.firstFromArray(\"${idleCountArray}\",\"0\")}}"
}

The JSONPath expression in the translationMap allows to do a search on entries with "qualifier" attribute equal to IDLE. The outcome of this request is an array (either empty if there were no users in IDLE state, or with a single value).
In the successTemplate, we can use the successTemplateUtils.firstFromArray macro to extract the first value of that array (if there were agents in IDLE state) or to use a default value (0 in this case) if the array was empty (when there are no agents in IDLE state).

Regards,

3 Likes

Thanks for the help that will work.

Thanks,
Darren

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