Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

REST API: TaskQueue Statistics


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:


TaskQueue RealTime Statistics

taskqueue-realtime-statistics page anchor

If you are only concerned with the real time statistics of your TaskQueue, you can utilize the below endpoint.

(warning)

Warning

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.

Resource URI

resource-uri page anchor

_10
GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics

URI parameters
WorkspaceSidtype: SID<WS>Not PII
Path Parameter

The SID of the Workspace with the TaskQueue to fetch.


TaskQueueSidtype: SID<WQ>Not PII
Path Parameter

The SID of the TaskQueue for which to fetch statistics.


TaskChanneltype: stringNot PII
Query Parameter

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:

Resource properties
activity_statisticstype: arrayNot PII

The number of current Workers by Activity.


longest_task_waiting_agetype: integerNot PII

The age of the longest waiting Task.


longest_task_waiting_sidtype: SID<WT>Not PII

The SID of the longest waiting Task.


longest_relative_task_age_in_queuetype: integerNot PII

The relative age in the TaskQueue for the longest waiting Task. Calculation is based on the time when the Task entered the TaskQueue.


longest_relative_task_sid_in_queuetype: SID<WT>Not PII

The Task SID of the Task waiting in the TaskQueue the longest. Calculation is based on the time when the Task entered the TaskQueue.


task_queue_sidtype: SID<WQ>Not PII

The SID of the TaskQueue from which these statistics were calculated.


tasks_by_prioritytype: objectNot PII

The number of Tasks by priority. For example: {"0": "10", "99": "5"} shows 10 Tasks at priority 0 and 5 at priority 99.


tasks_by_statustype: objectNot PII

The number of Tasks by their current status. For example: {"pending": "1", "reserved": "3", "assigned": "2", "completed": "5"}.


total_available_workerstype: integerNot PII

The total number of Workers available for Tasks in the TaskQueue.


total_eligible_workerstype: integerNot PII

The total number of Workers eligible for Tasks in the TaskQueue, independent of their Activity state.


total_taskstype: integerNot PII

The total number of Tasks.


workspace_sidtype: SID<WS>Not PII

The SID of the Workspace that contains the TaskQueue.


urltype: string<URI>Not PII

The absolute URL of the TaskQueue statistics resource.

Retrieving TaskQueue RealTime Statistics

retrieving-taskqueue-realtime-statistics page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.taskrouter.v1.workspaces('WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.taskQueues('WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.realTimeStatistics()
_12
.fetch()
_12
.then(task_queue_real_time_statistics => console.log(task_queue_real_time_statistics.activityStatistics));

Output

_42
{
_42
"longest_task_waiting_age": 100,
_42
"longest_task_waiting_sid": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"longest_relative_task_age_in_queue": 100,
_42
"longest_relative_task_sid_in_queue": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"tasks_by_status": {
_42
"reserved": 0,
_42
"pending": 0,
_42
"assigned": 0,
_42
"wrapping": 0
_42
},
_42
"total_eligible_workers": 100,
_42
"activity_statistics": [
_42
{
_42
"friendly_name": "Idle",
_42
"workers": 0,
_42
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_42
},
_42
{
_42
"friendly_name": "Busy",
_42
"workers": 9,
_42
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_42
},
_42
{
_42
"friendly_name": "Offline",
_42
"workers": 6,
_42
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_42
},
_42
{
_42
"friendly_name": "Reserved",
_42
"workers": 0,
_42
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_42
}
_42
],
_42
"tasks_by_priority": {},
_42
"total_tasks": 100,
_42
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"total_available_workers": 100,
_42
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/TaskQueues/WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/RealTimeStatistics"
_42
}


Bulk retrieval of TaskQueue RealTime Statistics

bulk-retrieval-of-taskqueue-realtime-statistics page anchor

To retrieve real-time statistics for multiple queues, you can utilize the below endpoint.


_10
POST /v1/Workspaces/{WorkspaceSid}/TaskQueues/RealTimeStatistics

Uri Parameters
WorkspaceSid

POST SID<WS> NOT PII

The unique SID identifier of the Workspace.
FieldRequired?Description
QueueSidsYesString array where each string represents one TaskQueueSID. (🏢 Not PII )

Real time statistics for TaskQueueSIDs provided as POST parameter include the following:

Resource properties
account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the TaskQueue resource.


workspace_sidtype: SID<WS>Not PII

The SID of the Workspace that contains the TaskQueue.


task_queue_datatype: arrayNot PII

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.


task_queue_response_counttype: integerNot PII

The number of TaskQueue statistics received in task_queue_data.


urltype: string<URI>Not PII

The absolute URL of the TaskQueue statistics resource.

The request body is validated for the following conditions:

  • If the number of TaskQueueSIDs in the request body is less than 1 or exceeds 50, an HTTP 400 error is returned.
  • If the request body contains invalid TaskQueueSIDs, an HTTP 400 error is returned.
  • If the request body includes valid TaskQueueSIDs that are not part of this account, these TaskQueueSIDs are included in the response but with zero values for all statistics.
  • This Bulk Retrieval API has a rate limit of 5 requests per second. If this rate limit is exceeded, an HTTP 429 error is returned.

Bulk retrieval of TaskQueue RealTime Statistics

bulk-retrieval-of-taskqueue-realtime-statistics-1 page anchor
curl

_10
curl --location --request POST 'https://taskrouter.twilio.com/v1/Workspaces/WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/TaskQueues/RealTimeStatistics' \
_10
--header 'Content-Type: application/json' \
_10
--data-raw '{
_10
"queueSids": [
_10
"WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10
"WQYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
_10
"WQZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
_10
]
_10
}'


TaskQueue Cumulative Statistics

taskqueue-cumulative-statistics page anchor

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.


_10
GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/CumulativeStatistics

URI parameters
WorkspaceSidtype: SID<WS>Not PII
Path Parameter

The SID of the Workspace with the TaskQueue to fetch.


TaskQueueSidtype: SID<WQ>Not PII
Path Parameter

The SID of the TaskQueue for which to fetch statistics.


EndDatetype: string<DATE TIME>Not PII
Query Parameter

Only calculate statistics from this date and time and earlier, specified in GMT as an ISO 8601(link takes you to an external page) date-time.


Minutestype: integerNot PII
Query Parameter

Only calculate statistics since this many minutes in the past. The default is 15 minutes.


StartDatetype: string<DATE TIME>Not PII
Query Parameter

Only calculate statistics from this date and time and later, specified in ISO 8601(link takes you to an external page) format.


TaskChanneltype: stringNot PII
Query Parameter

Only calculate cumulative statistics on this TaskChannel. Can be the TaskChannel's SID or its unique_name, such as voice, sms, or default.


SplitByWaitTimetype: stringNot PII
Query Parameter

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:

Resource properties
account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the TaskQueue resource.


avg_task_acceptance_timetype: integerNot PII

The average time in seconds between Task creation and acceptance.


start_timetype: string<DATE TIME>Not PII

The beginning of the interval during which these statistics were calculated, in ISO 8601(link takes you to an external page) format.


end_timetype: string<DATE TIME>Not PII

The end of the interval during which these statistics were calculated, in ISO 8601(link takes you to an external page) format.


reservations_createdtype: integerNot PII

The total number of Reservations created for Tasks in the TaskQueue.


reservations_acceptedtype: integerNot PII

The total number of Reservations accepted for Tasks in the TaskQueue.


reservations_rejectedtype: integerNot PII

The total number of Reservations rejected for Tasks in the TaskQueue.


reservations_timed_outtype: integerNot PII

The total number of Reservations that timed out for Tasks in the TaskQueue.


reservations_canceledtype: integerNot PII

The total number of Reservations canceled for Tasks in the TaskQueue.


reservations_rescindedtype: integerNot PII

The total number of Reservations rescinded.


split_by_wait_timetype: objectNot PII

A list of objects that describe the number of Tasks canceled and reservations accepted above and below the thresholds specified in seconds.


task_queue_sidtype: SID<WQ>Not PII

The SID of the TaskQueue from which these statistics were calculated.


wait_duration_until_acceptedtype: objectNot PII

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.


wait_duration_until_canceledtype: objectNot PII

The wait duration statistics (avg, min, max, total) for Tasks canceled while in the TaskQueue.


wait_duration_in_queue_until_acceptedtype: objectNot PII

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.


tasks_canceledtype: integerNot PII

The total number of Tasks canceled in the TaskQueue.


tasks_completedtype: integerNot PII

The total number of Tasks completed in the TaskQueue.


tasks_deletedtype: integerNot PII

The total number of Tasks deleted in the TaskQueue.


tasks_enteredtype: integerNot PII

The total number of Tasks entered into the TaskQueue.


tasks_movedtype: integerNot PII

The total number of Tasks that were moved from one queue to another.


workspace_sidtype: SID<WS>Not PII

The SID of the Workspace that contains the TaskQueue.


urltype: string<URI>Not PII

The absolute URL of the TaskQueue statistics resource.

(information)

Info

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.

Retrieving TaskQueue Cumulative Statistics

retrieving-taskqueue-cumulative-statistics page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.taskrouter.v1.workspaces('WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.taskQueues('WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.cumulativeStatistics()
_12
.fetch()
_12
.then(task_queue_cumulative_statistics => console.log(task_queue_cumulative_statistics.avgTaskAcceptanceTime));

Output

_60
{
_60
"reservations_created": 100,
_60
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"reservations_rejected": 100,
_60
"tasks_completed": 100,
_60
"end_time": "2015-07-30T20:00:00Z",
_60
"tasks_entered": 100,
_60
"tasks_canceled": 100,
_60
"reservations_accepted": 100,
_60
"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"reservations_timed_out": 100,
_60
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/TaskQueues/WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/CumulativeStatistics",
_60
"wait_duration_until_canceled": {
_60
"avg": 0,
_60
"min": 0,
_60
"max": 0,
_60
"total": 0
_60
},
_60
"wait_duration_until_accepted": {
_60
"avg": 0,
_60
"min": 0,
_60
"max": 0,
_60
"total": 0
_60
},
_60
"wait_duration_in_queue_until_accepted": {
_60
"avg": 0,
_60
"min": 0,
_60
"max": 0,
_60
"total": 0
_60
},
_60
"split_by_wait_time": {
_60
"5": {
_60
"above": {
_60
"tasks_canceled": 0,
_60
"reservations_accepted": 0
_60
},
_60
"below": {
_60
"tasks_canceled": 0,
_60
"reservations_accepted": 0
_60
}
_60
},
_60
"10": {
_60
"above": {
_60
"tasks_canceled": 0,
_60
"reservations_accepted": 0
_60
},
_60
"below": {
_60
"tasks_canceled": 0,
_60
"reservations_accepted": 0
_60
}
_60
}
_60
},
_60
"start_time": "2015-07-30T20:00:00Z",
_60
"tasks_moved": 100,
_60
"reservations_canceled": 100,
_60
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_60
"tasks_deleted": 100,
_60
"reservations_rescinded": 100,
_60
"avg_task_acceptance_time": 100
_60
}


TaskQueue Instance Statistics

taskqueue-instance-statistics page anchor

_10
GET /v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics

URI parameters
WorkspaceSidtype: SID<WS>Not PII
Path Parameter

The SID of the Workspace with the TaskQueue to fetch.


TaskQueueSidtype: SID<WQ>Not PII
Path Parameter

The SID of the TaskQueue for which to fetch statistics.


EndDatetype: string<DATE TIME>Not PII
Query Parameter

Only calculate statistics from this date and time and earlier, specified in GMT as an ISO 8601(link takes you to an external page) date-time.


Minutestype: integerNot PII
Query Parameter

Only calculate statistics since this many minutes in the past. The default is 15 minutes.


StartDatetype: string<DATE TIME>Not PII
Query Parameter

Only calculate statistics from this date and time and later, specified in ISO 8601(link takes you to an external page) format.


TaskChanneltype: stringNot PII
Query Parameter

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.


SplitByWaitTimetype: stringNot PII
Query Parameter

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.

(warning)

Warning

Minutes cannot be used in combination with StartDate and EndDate parameters. If no parameters are passed, 15 minutes will be the default.

Resource properties
account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the TaskQueue resource.


cumulativetype: objectNot PII

An object that contains the cumulative statistics for the TaskQueue.


realtimetype: objectNot PII

An object that contains the real-time statistics for the TaskQueue.


task_queue_sidtype: SID<WQ>Not PII

The SID of the TaskQueue from which these statistics were calculated.


workspace_sidtype: SID<WS>Not PII

The SID of the Workspace that contains the TaskQueue.


urltype: string<URI>Not PII

The absolute URL of the TaskQueue statistics resource.

Retrieving TaskQueue Instance Statistics

retrieving-taskqueue-instance-statistics page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.taskrouter.v1.workspaces('WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.taskQueues('WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.statistics()
_12
.fetch()
_12
.then(task_queue_statistics => console.log(task_queue_statistics.cumulative));

Output

_66
{
_66
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/TaskQueues/WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Statistics",
_66
"cumulative": {
_66
"avg_task_acceptance_time": 0.0,
_66
"end_time": "2015-08-18T08:42:34Z",
_66
"reservations_accepted": 0,
_66
"reservations_canceled": 0,
_66
"reservations_created": 0,
_66
"reservations_rejected": 0,
_66
"reservations_rescinded": 0,
_66
"reservations_timed_out": 0,
_66
"start_time": "2015-08-18T08:27:34Z",
_66
"tasks_canceled": 0,
_66
"tasks_deleted": 0,
_66
"tasks_entered": 0,
_66
"tasks_moved": 0
_66
},
_66
"realtime": {
_66
"activity_statistics": [
_66
{
_66
"friendly_name": "Offline",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Idle",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "80fa2beb-3a05-11e5-8fc8-98e0d9a1eb73",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Reserved",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Busy",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "817ca1c5-3a05-11e5-9292-98e0d9a1eb73",
_66
"sid": "WAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workers": 0
_66
}
_66
],
_66
"longest_task_waiting_age": 0,
_66
"longest_task_waiting_sid": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"tasks_by_status": {
_66
"assigned": 0,
_66
"pending": 0,
_66
"reserved": 0,
_66
"wrapping": 0
_66
},
_66
"total_available_workers": 0,
_66
"total_eligible_workers": 0,
_66
"total_tasks": 0
_66
},
_66
"task_queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_66
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_66
}


Rate this page: