Legacy Dev Forum Posts

 View Only

Sign Up

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

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

    Posted 06-05-2025 18:20

    Darren_Sawyer | 2021-09-02 14:41:19 UTC | #1

    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|attachment (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


    Jerome.Saint-Marc | 2021-09-14 13:06:33 UTC | #2

    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,


    Darren_Sawyer | 2021-09-14 13:08:22 UTC | #3

    Thanks for the help that will work.

    Thanks, Darren


    system | 2021-10-15 13:09:00 UTC | #4

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