TaskRouter provides real time and historical statistics for TaskQueues. Historical statistics allow you to analyze data from the past 30 days.
Twilio offers the following APIs for TaskQueue statistics:
If you are only concerned with the real time statistics of your TaskQueue, you can utilize the below endpoint.
We recommended leveraging caching when utilizing this endpoint from your backend application to ensure this endpoint can support your scaling needs.
In scenarios where this endpoint would be used from a client application, we recommend implementing a sync layer, e.g., via Twilio Sync, to help synchronize this endpoint's state across all clients, and to ensure this endpoint can scale with your user growth.
1GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics2
The SID of the Workspace with the TaskQueue to fetch.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the TaskQueue for which to fetch statistics.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The TaskChannel for which to fetch statistics. Can be the TaskChannel's SID or its unique_name
, such as voice
, sms
, or default
.
Real time statistics relating to a TaskQueue include the following:
The SID of the Account that created the TaskQueue resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the longest waiting Task.
^WT[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The relative age in the TaskQueue for the longest waiting Task. Calculation is based on the time when the Task entered the TaskQueue.
0
The Task SID of the Task waiting in the TaskQueue the longest. Calculation is based on the time when the Task entered the TaskQueue.
^WT[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the TaskQueue from which these statistics were calculated.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The number of Tasks by priority. For example: {"0": "10", "99": "5"}
shows 10 Tasks at priority 0 and 5 at priority 99.
The number of Tasks by their current status. For example: {"pending": "1", "reserved": "3", "assigned": "2", "completed": "5"}
.
The total number of Workers in the TaskQueue with an available
status. Workers with an available
status may already have active interactions or may have none.
0
The total number of Workers eligible for Tasks in the TaskQueue, independent of their Activity state.
0
The SID of the Workspace that contains the TaskQueue.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The absolute URL of the TaskQueue statistics resource.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchTaskQueueRealTimeStatistics() {11const realTimeStatistic = await client.taskrouter.v112.workspaces("WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.taskQueues("WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")14.realTimeStatistics()15.fetch();1617console.log(realTimeStatistic.accountSid);18}1920fetchTaskQueueRealTimeStatistics();
1{2"longest_task_waiting_age": 100,3"longest_task_waiting_sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"longest_relative_task_age_in_queue": 100,5"longest_relative_task_sid_in_queue": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",7"tasks_by_status": {8"reserved": 0,9"pending": 0,10"assigned": 0,11"wrapping": 012},13"total_eligible_workers": 100,14"activity_statistics": [15{16"friendly_name": "Idle",17"workers": 0,18"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"19},20{21"friendly_name": "Busy",22"workers": 9,23"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"24},25{26"friendly_name": "Offline",27"workers": 6,28"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"29},30{31"friendly_name": "Reserved",32"workers": 0,33"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"34}35],36"tasks_by_priority": {},37"total_tasks": 100,38"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",39"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",40"total_available_workers": 100,41"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/RealTimeStatistics"42}
To retrieve real-time statistics for multiple queues, you can utilize the below endpoint.
1POST /v1/Workspaces/{WorkspaceSid}/TaskQueues/RealTimeStatistics2
Uri Parameters |
---|
WorkspaceSidPOST SID<WS> NOT PII The unique SID identifier of the Workspace. |
Field | Required? | Description |
---|---|---|
QueueSids | Yes | String array where each string represents one TaskQueueSID. (🏢 Not PII ) |
Real time statistics for TaskQueueSIDs provided as POST
parameter include the following:
The SID of the Account that created the TaskQueue resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Workspace that contains the TaskQueue.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The real-time statistics for each requested TaskQueue SID. task_queue_data
returns the following attributes:
task_queue_sid
: The SID of the TaskQueue from which these statistics were calculated.
total_available_workers
: The total number of Workers available for Tasks in the TaskQueue.
total_eligible_workers
: The total number of Workers eligible for Tasks in the TaskQueue, regardless of their Activity state.
total_tasks
: The total number of Tasks.
longest_task_waiting_age
: The age of the longest waiting Task.
longest_task_waiting_sid
: The SID of the longest waiting Task.
tasks_by_status
: The number of Tasks grouped by their current status.
tasks_by_priority
: The number of Tasks grouped by priority.
activity_statistics
: The number of current Workers grouped by Activity.
The number of TaskQueue statistics received in task_queue_data.
0
The absolute URL of the TaskQueue statistics resource.
The request body is validated for the following conditions:
1curl --location --request POST 'https://taskrouter.twilio.com/v1/Workspaces/WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/TaskQueues/RealTimeStatistics' \2--header 'Content-Type: application/json' \3--data-raw '{4"queueSids": [5"WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",6"WQYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",7"WQZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"8]9}'
If you are only concerned with the cumulative statistics over a certain time period, you can utilize the below endpoint. Cumulative statistics allow you to analyze data from the past 30 days.
1GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/CumulativeStatistics2
The SID of the Workspace with the TaskQueue to fetch.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the TaskQueue for which to fetch statistics.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
Only calculate statistics from this date and time and earlier, specified in GMT as an ISO 8601 date-time.
Only calculate statistics since this many minutes in the past. The default is 15 minutes.
Only calculate statistics from this date and time and later, specified in ISO 8601 format.
Only calculate cumulative statistics on this TaskChannel. Can be the TaskChannel's SID or its unique_name
, such as voice
, sms
, or default
.
A comma separated list of values that describes the thresholds, in seconds, to calculate statistics on. For each threshold specified, the number of Tasks canceled and reservations accepted above and below the specified thresholds in seconds are computed. TaskRouter will calculate statistics on up to 10,000 Tasks/Reservations for any given threshold.
Cumulative statistics relating to a TaskQueue include the following over the interval:
The SID of the Account that created the TaskQueue resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The average time in seconds between Task creation and acceptance.
0
The beginning of the interval during which these statistics were calculated, in ISO 8601 format.
The end of the interval during which these statistics were calculated, in ISO 8601 format.
The total number of Reservations created for Tasks in the TaskQueue.
0
The total number of Reservations accepted for Tasks in the TaskQueue.
0
The total number of Reservations rejected for Tasks in the TaskQueue.
0
The total number of Reservations that timed out for Tasks in the TaskQueue.
0
The total number of Reservations canceled for Tasks in the TaskQueue.
0
A list of objects that describe the number of Tasks canceled and reservations accepted above and below the thresholds specified in seconds.
The SID of the TaskQueue from which these statistics were calculated.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The wait duration statistics (avg
, min
, max
, total
) for Tasks accepted while in the TaskQueue. Calculation is based on the time when the Tasks were created. For transfers, the wait duration is counted from the moment the Task was created, and not from when the transfer was initiated.
The wait duration statistics (avg
, min
, max
, total
) for Tasks canceled while in the TaskQueue.
The relative wait duration statistics (avg
, min
, max
, total
) for Tasks accepted while in the TaskQueue. Calculation is based on the time when the Tasks entered the TaskQueue.
The total number of Tasks completed in the TaskQueue.
0
The total number of Tasks that were moved from one queue to another.
0
The SID of the Workspace that contains the TaskQueue.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The absolute URL of the TaskQueue statistics resource.
Note that for transfers, the splitByWaitTime does not include the wait time post transfer, and hence transfers should not impact SLA calculations based on the above endpoint.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchTaskQueueCumulativeStatistics() {11const cumulativeStatistic = await client.taskrouter.v112.workspaces("WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.taskQueues("WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")14.cumulativeStatistics()15.fetch();1617console.log(cumulativeStatistic.accountSid);18}1920fetchTaskQueueCumulativeStatistics();
1{2"reservations_created": 100,3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"reservations_rejected": 100,5"tasks_completed": 100,6"end_time": "2015-07-30T20:00:00Z",7"tasks_entered": 100,8"tasks_canceled": 100,9"reservations_accepted": 100,10"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",11"reservations_timed_out": 100,12"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/CumulativeStatistics",13"wait_duration_until_canceled": {14"avg": 0,15"min": 0,16"max": 0,17"total": 018},19"wait_duration_until_accepted": {20"avg": 0,21"min": 0,22"max": 0,23"total": 024},25"wait_duration_in_queue_until_accepted": {26"avg": 0,27"min": 0,28"max": 0,29"total": 030},31"split_by_wait_time": {32"5": {33"above": {34"tasks_canceled": 0,35"reservations_accepted": 036},37"below": {38"tasks_canceled": 0,39"reservations_accepted": 040}41},42"10": {43"above": {44"tasks_canceled": 0,45"reservations_accepted": 046},47"below": {48"tasks_canceled": 0,49"reservations_accepted": 050}51}52},53"start_time": "2015-07-30T20:00:00Z",54"tasks_moved": 100,55"reservations_canceled": 100,56"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",57"tasks_deleted": 100,58"reservations_rescinded": 100,59"avg_task_acceptance_time": 10060}
1GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics2
The SID of the Workspace with the TaskQueue to fetch.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the TaskQueue for which to fetch statistics.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
Only calculate statistics from this date and time and earlier, specified in GMT as an ISO 8601 date-time.
Only calculate statistics since this many minutes in the past. The default is 15 minutes.
Only calculate statistics from this date and time and later, specified in ISO 8601 format.
Only calculate real-time and cumulative statistics for the specified TaskChannel. Can be the TaskChannel's SID or its unique_name
, such as voice
, sms
, or default
.
A comma separated list of values that describes the thresholds, in seconds, to calculate statistics on. For each threshold specified, the number of Tasks canceled and reservations accepted above and below the specified thresholds in seconds are computed.
Minutes
cannot be used in combination with StartDate
and EndDate
parameters. If no parameters are passed, 15 minutes will be the default.
The SID of the Account that created the TaskQueue resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the TaskQueue from which these statistics were calculated.
^WQ[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Workspace that contains the TaskQueue.
^WS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The absolute URL of the TaskQueue statistics resource.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchTaskQueueStatistics() {11const statistic = await client.taskrouter.v112.workspaces("WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.taskQueues("WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")14.statistics()15.fetch();1617console.log(statistic.accountSid);18}1920fetchTaskQueueStatistics();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Statistics",4"cumulative": {5"avg_task_acceptance_time": 0,6"end_time": "2015-08-18T08:42:34Z",7"reservations_accepted": 0,8"reservations_canceled": 0,9"reservations_created": 0,10"reservations_rejected": 0,11"reservations_rescinded": 0,12"reservations_timed_out": 0,13"start_time": "2015-08-18T08:27:34Z",14"tasks_canceled": 0,15"tasks_deleted": 0,16"tasks_entered": 0,17"tasks_moved": 018},19"realtime": {20"activity_statistics": [21{22"friendly_name": "Offline",23"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",24"workers": 025},26{27"friendly_name": "Idle",28"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",29"workers": 030},31{32"friendly_name": "80fa2beb-3a05-11e5-8fc8-98e0d9a1eb73",33"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",34"workers": 035},36{37"friendly_name": "Reserved",38"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",39"workers": 040},41{42"friendly_name": "Busy",43"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",44"workers": 045},46{47"friendly_name": "817ca1c5-3a05-11e5-9292-98e0d9a1eb73",48"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",49"workers": 050}51],52"longest_task_waiting_age": 0,53"longest_task_waiting_sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",54"tasks_by_status": {55"assigned": 0,56"pending": 0,57"reserved": 0,58"wrapping": 059},60"total_available_workers": 0,61"total_eligible_workers": 0,62"total_tasks": 063},64"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",65"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"66}