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

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required
Not PII

The SID of the Workspace with the TaskQueue to fetch.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

TaskQueueSidSID<WQ>required

The SID of the TaskQueue for which to fetch statistics.

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
TaskChannelstringOptional

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:

Property nameTypePIIDescription
account_sidSID<AC>

The SID of the Account that created the TaskQueue resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

activity_statisticsarray

The number of current Workers by Activity.


longest_task_waiting_ageinteger

The age of the longest waiting Task.


longest_task_waiting_sidSID<WT>

The SID of the longest waiting Task.

Pattern: ^WT[0-9a-fA-F]{32}$Min length: 34Max length: 34

longest_relative_task_age_in_queueinteger

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_queueSID<WT>

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

Pattern: ^WT[0-9a-fA-F]{32}$Min length: 34Max length: 34

task_queue_sidSID<WQ>

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

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34

tasks_by_priorityobject

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_statusobject

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


total_available_workersinteger

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


total_eligible_workersinteger

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


total_tasksinteger

The total number of Tasks.


workspace_sidSID<WS>

The SID of the Workspace that contains the TaskQueue.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

urlstring<uri>

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

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

Output

_42
{
_42
"longest_task_waiting_age": 100,
_42
"longest_task_waiting_sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_42
"longest_relative_task_age_in_queue": 100,
_42
"longest_relative_task_sid_in_queue": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_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": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_42
},
_42
{
_42
"friendly_name": "Busy",
_42
"workers": 9,
_42
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_42
},
_42
{
_42
"friendly_name": "Offline",
_42
"workers": 6,
_42
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_42
},
_42
{
_42
"friendly_name": "Reserved",
_42
"workers": 0,
_42
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_42
}
_42
],
_42
"tasks_by_priority": {},
_42
"total_tasks": 100,
_42
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_42
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_42
"total_available_workers": 100,
_42
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/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:

Property nameTypePIIDescription
account_sidSID<AC>

The SID of the Account that created the TaskQueue resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

workspace_sidSID<WS>

The SID of the Workspace that contains the TaskQueue.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

task_queue_dataarray

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_countinteger

The number of TaskQueue statistics received in task_queue_data.


urlstring<uri>

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

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the TaskQueue to fetch.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

TaskQueueSidSID<WQ>required

The SID of the TaskQueue for which to fetch statistics.

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
EndDatestring<date-time>Optional

MinutesintegerOptional

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


StartDatestring<date-time>Optional

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


TaskChannelstringOptional

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


SplitByWaitTimestringOptional

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:

Property nameTypePIIDescription
account_sidSID<AC>

The SID of the Account that created the TaskQueue resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

avg_task_acceptance_timeinteger

The average time in seconds between Task creation and acceptance.


start_timestring<date-time>

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


end_timestring<date-time>

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


reservations_createdinteger

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


reservations_acceptedinteger

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


reservations_rejectedinteger

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


reservations_timed_outinteger

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


reservations_canceledinteger

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


reservations_rescindedinteger

The total number of Reservations rescinded.


split_by_wait_timeobject

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


task_queue_sidSID<WQ>

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

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34

wait_duration_until_acceptedobject

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_canceledobject

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


wait_duration_in_queue_until_acceptedobject

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_canceledinteger

The total number of Tasks canceled in the TaskQueue.


tasks_completedinteger

The total number of Tasks completed in the TaskQueue.


tasks_deletedinteger

The total number of Tasks deleted in the TaskQueue.


tasks_enteredinteger

The total number of Tasks entered into the TaskQueue.


tasks_movedinteger

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


workspace_sidSID<WS>

The SID of the Workspace that contains the TaskQueue.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

urlstring<uri>

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

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

Output

_60
{
_60
"reservations_created": 100,
_60
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_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/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/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

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the TaskQueue to fetch.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

TaskQueueSidSID<WQ>required

The SID of the TaskQueue for which to fetch statistics.

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
EndDatestring<date-time>Optional

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.


MinutesintegerOptional

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


StartDatestring<date-time>Optional

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


TaskChannelstringOptional

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.


SplitByWaitTimestringOptional

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.

Property nameTypePIIDescription
account_sidSID<AC>

The SID of the Account that created the TaskQueue resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

cumulativeobject

An object that contains the cumulative statistics for the TaskQueue.


realtimeobject

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


task_queue_sidSID<WQ>

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

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34

workspace_sidSID<WS>

The SID of the Workspace that contains the TaskQueue.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34

urlstring<uri>

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

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

Output

_66
{
_66
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Statistics",
_66
"cumulative": {
_66
"avg_task_acceptance_time": 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": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Idle",
_66
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "80fa2beb-3a05-11e5-8fc8-98e0d9a1eb73",
_66
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Reserved",
_66
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "Busy",
_66
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
},
_66
{
_66
"friendly_name": "817ca1c5-3a05-11e5-9292-98e0d9a1eb73",
_66
"sid": "WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_66
"workers": 0
_66
}
_66
],
_66
"longest_task_waiting_age": 0,
_66
"longest_task_waiting_sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_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: