Skip to contentSkip to navigationSkip to topbar
On this page

Task Resource


A Task represents a single item of work waiting to be processed. Tasks can represent whatever type of work is important for your team. Twilio applications can create tasks from phone calls or SMS messages. Your CRM or ticketing system can generate tasks from emails or chat messages sent in by your customers. Your own applications can create custom tasks representing whatever unique work your users handle.


Task Properties

task-properties page anchor
(warning)

Warning

Pagination is not supported under this resource. Please avoid usage of the page query parameter.

Task Attributes

task-attributes page anchor

Every Task has attributes, allowing you to pass along whatever data is required for your application to route the task and take the appropriate action on assignment. Attributes are expressed in JSON data, for example:

1
{
2
"type": "call",
3
"contact": "+15558675309",
4
"customer-value": "gold",
5
"task-reason": "support",
6
"callSid": "CA42ed11..."
7
}

Tasks have a version, represented in the ETag header when you POST or GET the Task Resource. ETags are a method of showing whether a resource has changed; if the ETag is the same, then the resource is the same.

Tasks can also use the If-Match header when updating or deleting a Task Resource. If the ETag does not match the provided version, the operation will fail with a 412 response. You can then GET the latest version of the Task and try updating it again. When the If-Match is not provided, the Task will update without a check.

You can read about Task Mutation and Conflict Resolution to learn about working with Task versions.

A Task does not have an explicit Lifecycle property, but it's an important concept for understanding how Tasks work. A Task's lifecycle is controlled by a Workflow, which will manage the Task's priority and find matching Workers to handle the Task. The Task State page and Workflows and Assignment page provide more detail on the Task lifecycle.

(information)

Info

If you wish to update the assignment status of a task to wrapping or completed and also update its attributes, you will need to send two API requests: one for changing the assignment status, and one for updating the attributes.

Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>

Optional

Not PII

The SID of the Account that created the Task resource.

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

ageinteger

Optional

The number of seconds since the Task was created.

Default: 0

assignment_statusenum<string>

Optional

The current status of the Task's assignment. Can be: pending, reserved, assigned, canceled, wrapping, or completed.

Possible values:
pendingreservedassignedcanceledcompletedwrapping

attributesstring

Optional

PII MTL: 30 days

The JSON string with custom attributes of the work. Note If this property has been assigned a value, it will only be displayed in FETCH action that returns a single resource. Otherwise, it will be null.


addonsstring

Optional

An object that contains the Add-on data for all installed Add-ons.


date_updatedstring<date-time>

Optional

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.


task_queue_entered_datestring<date-time>

Optional

The date and time in GMT when the Task entered the TaskQueue, specified in ISO 8601(link takes you to an external page) format.


priorityinteger

Optional

The current priority score of the Task as assigned to a Worker by the workflow. Tasks with higher priority values will be assigned before Tasks with lower values.

Default: 0

reasonstring

Optional

The reason the Task was canceled or completed, if applicable.


sidSID<WT>

Optional

The unique string that we created to identify the Task resource.

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

task_queue_sidSID<WQ>

Optional

The SID of the TaskQueue.

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

task_queue_friendly_namestring

Optional

The friendly name of the TaskQueue.


task_channel_sidSID<TC>

Optional

The SID of the TaskChannel.

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

task_channel_unique_namestring

Optional

The unique name of the TaskChannel.


timeoutinteger

Optional

The amount of time in seconds that the Task can live before being assigned.

Default: 0

workflow_sidSID<WW>

Optional

The SID of the Workflow that is controlling the Task.

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

workflow_friendly_namestring

Optional

The friendly name of the Workflow that is controlling the Task.


workspace_sidSID<WS>

Optional

The SID of the Workspace that contains the Task.

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

urlstring<uri>

Optional

The absolute URL of the Task resource.


linksobject<uri-map>

Optional

The URLs of related resources.


virtual_start_timestring<date-time>

Optional

The date and time in GMT indicating the ordering for routing of the Task specified in ISO 8601(link takes you to an external page) format.


ignore_capacityboolean

Optional

A boolean that indicates if the Task should respect a Worker's capacity and availability during assignment. This field can only be used when the RoutingTarget field is set to a Worker SID. By setting IgnoreCapacity to a value of true, 1, or yes, the Task will be routed to the Worker without respecting their capacity and availability. Any other value will enforce the Worker's capacity and availability. The default value of IgnoreCapacity is true when the RoutingTarget is set to a Worker SID.


routing_targetstring

Optional

A SID of a Worker, Queue, or Workflow to route a Task to


POST https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace that the new Task belongs to.

Pattern: ^WS[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Timeoutinteger

Optional

The amount of time in seconds the new task can live before being assigned. Can be up to a maximum of 2 weeks (1,209,600 seconds). The default value is 24 hours (86,400 seconds). On timeout, the task.canceled event will fire with description Task TTL Exceeded.


Priorityinteger

Optional

The priority to assign the new task and override the default. When supplied, the new Task will have this priority unless it matches a Workflow Target with a Priority set. When not supplied, the new Task will have the priority of the matching Workflow Target. Value can be 0 to 2^31^ (2,147,483,647).


TaskChannelstring

Optional

When MultiTasking is enabled, specify the TaskChannel by passing either its unique_name or sid. Default value is default.


WorkflowSidSID<WW>

Optional

The SID of the Workflow that you would like to handle routing for the new Task. If there is only one Workflow defined for the Workspace that you are posting the new task to, this parameter is optional.

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

Attributesstring

Optional

A URL-encoded JSON string with the attributes of the new task. This value is passed to the Workflow's assignment_callback_url when the Task is assigned to a Worker. For example: { "task_type": "call", "twilio_call_sid": "CAxxx", "customer_ticket_number": "12345" }.


VirtualStartTimestring<date-time>

Optional

The virtual start time to assign the new task and override the default. When supplied, the new task will have this virtual start time. When not supplied, the new task will have the virtual start time equal to date_created. Value can't be in the future or before the year of 1900.


RoutingTargetstring

Optional

A SID of a Worker, Queue, or Workflow to route a Task to


IgnoreCapacitystring

Optional

A boolean that indicates if the Task should respect a Worker's capacity and availability during assignment. This field can only be used when the RoutingTarget field is set to a Worker SID. By setting IgnoreCapacity to a value of true, 1, or yes, the Task will be routed to the Worker without respecting their capacity and availability. Any other value will enforce the Worker's capacity and availability. The default value of IgnoreCapacity is true when the RoutingTarget is set to a Worker SID.


TaskQueueSidSID<WQ>

Optional

The SID of the TaskQueue in which the Task belongs

Pattern: ^WQ[0-9a-fA-F]{32}$Min length: 34Max length: 34
Create a TaskLink to code sample: Create a Task
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createTask() {
11
const task = await client.taskrouter.v1
12
.workspaces("WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.tasks.create({
14
attributes: JSON.stringify({ type: "support" }),
15
workflowSid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
16
});
17
18
console.log(task.accountSid);
19
}
20
21
createTask();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"age": 25200,
4
"assignment_status": "pending",
5
"attributes": "{\"type\":\"support\"}",
6
"date_created": "2014-05-14T18:50:02Z",
7
"date_updated": "2014-05-15T07:26:06Z",
8
"task_queue_entered_date": null,
9
"virtual_start_time": "2014-05-14T18:50:02Z",
10
"priority": 1,
11
"reason": "Test Reason",
12
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"task_channel_unique_name": "unique",
16
"timeout": 60,
17
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
19
"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
20
"workflow_friendly_name": "Example Workflow",
21
"task_queue_friendly_name": "Example Task Queue",
22
"ignore_capacity": false,
23
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
24
"addons": "{}",
25
"required_attention": 0,
26
"links": {
27
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
31
}
32
}
(warning)

Warning

Please contact us(link takes you to an external page) if your use case will require more than 25,000 in-flight Tasks for any given Workspace. We define in-flight Tasks as all Tasks that are not in status canceled or completed.


GET https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the Task to fetch.

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

SidSID<WT>required

The SID of the Task resource to fetch.

Pattern: ^WT[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchTask() {
11
const task = await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks("WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.fetch();
15
16
console.log(task.accountSid);
17
}
18
19
fetchTask();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"age": 25200,
4
"assignment_status": "pending",
5
"attributes": "{\"body\": \"hello\"}",
6
"date_created": "2014-05-14T18:50:02Z",
7
"date_updated": "2014-05-15T07:26:06Z",
8
"task_queue_entered_date": "2014-05-14T18:50:02Z",
9
"virtual_start_time": "2014-05-14T18:50:02Z",
10
"priority": 0,
11
"reason": "Test Reason",
12
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"task_channel_unique_name": "task-channel",
16
"timeout": 60,
17
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
19
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20
"workflow_friendly_name": "Test Workflow",
21
"task_queue_friendly_name": "Test Queue",
22
"ignore_capacity": false,
23
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
24
"addons": "{}",
25
"required_attention": 0,
26
"links": {
27
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
31
}
32
}

Read multiple Task resources

read-multiple-task-resources page anchor
GET https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the Tasks to read.

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

Optional

The priority value of the Tasks to read. Returns the list of all Tasks in the Workspace with the specified priority.


AssignmentStatusarray[string]

Optional

The assignment_status of the Tasks you want to read. Can be: pending, reserved, assigned, canceled, wrapping, or completed. Returns all Tasks in the Workspace with the specified assignment_status.


WorkflowSidSID<WW>

Optional

The SID of the Workflow with the Tasks to read. Returns the Tasks controlled by the Workflow identified by this SID.

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

WorkflowNamestring

Optional

The friendly name of the Workflow with the Tasks to read. Returns the Tasks controlled by the Workflow identified by this friendly name.


TaskQueueSidSID<WQ>

Optional

The SID of the TaskQueue with the Tasks to read. Returns the Tasks waiting in the TaskQueue identified by this SID.

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

TaskQueueNamestring

Optional

The friendly_name of the TaskQueue with the Tasks to read. Returns the Tasks waiting in the TaskQueue identified by this friendly name.


EvaluateTaskAttributesstring

Optional

The attributes of the Tasks to read. Returns the Tasks that match the attributes specified in this parameter.


RoutingTargetstring

Optional

A SID of a Worker, Queue, or Workflow to route a Task to


Orderingstring

Optional

How to order the returned Task resources. By default, Tasks are sorted by ascending DateCreated. This value is specified as: Attribute:Order, where Attribute can be either DateCreated, Priority, or VirtualStartTime and Order can be either asc or desc. For example, Priority:desc returns Tasks ordered in descending order of their Priority. Pairings of sort orders can be specified in a comma-separated list such as Priority:desc,DateCreated:asc, which returns the Tasks in descending Priority order and ascending DateCreated Order. The only ordering pairing not allowed is DateCreated and VirtualStartTime.


HasAddonsboolean

Optional

Whether to read Tasks with Add-ons. If true, returns only Tasks with Add-ons. If false, returns only Tasks without Add-ons.


PageSizeinteger

Optional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

Pageinteger

Optional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstring

Optional

The page token. This is provided by the API.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listTask() {
11
const tasks = await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks.list({ limit: 20 });
14
15
tasks.forEach((t) => console.log(t.accountSid));
16
}
17
18
listTask();

Output

1
{
2
"meta": {
3
"first_page_url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks?TaskQueueSid=WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&RoutingTarget=WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&TaskQueueName=task_queue_name&WorkflowName=workflow_name&WorkflowSid=WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&AssignmentStatus=pending%2Creserved&Priority=1&PageSize=50&Page=0",
4
"key": "tasks",
5
"next_page_url": null,
6
"page": 0,
7
"page_size": 50,
8
"previous_page_url": null,
9
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks?TaskQueueSid=WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&RoutingTarget=WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&TaskQueueName=task_queue_name&WorkflowName=workflow_name&WorkflowSid=WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&AssignmentStatus=pending%2Creserved&Priority=1&PageSize=50&Page=0"
10
},
11
"tasks": [
12
{
13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"age": 25200,
15
"assignment_status": "pending",
16
"attributes": "{\"body\": \"hello\"}",
17
"date_created": "2014-05-14T14:26:54Z",
18
"date_updated": "2014-05-15T16:03:42Z",
19
"task_queue_entered_date": "2014-05-14T14:26:54Z",
20
"virtual_start_time": "2014-05-14T14:26:54Z",
21
"priority": 0,
22
"reason": "Test Reason",
23
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
24
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
26
"task_channel_unique_name": "task-channel",
27
"timeout": 60,
28
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
31
"workflow_friendly_name": "Test Workflow",
32
"task_queue_friendly_name": "Test Queue",
33
"ignore_capacity": false,
34
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
35
"addons": "{}",
36
"required_attention": 0,
37
"links": {
38
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
39
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
40
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
41
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
42
}
43
}
44
]
45
}
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listTask() {
11
const tasks = await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks.list({
14
evaluateTaskAttributes:
15
'(language == "en" OR language == "fr") AND skill_rating >= 5.1',
16
limit: 20,
17
});
18
19
tasks.forEach((t) => console.log(t.accountSid));
20
}
21
22
listTask();

Output

1
{
2
"meta": {
3
"first_page_url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks?TaskQueueSid=WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&RoutingTarget=WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&TaskQueueName=task_queue_name&WorkflowName=workflow_name&WorkflowSid=WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&AssignmentStatus=pending%2Creserved&Priority=1&PageSize=50&Page=0",
4
"key": "tasks",
5
"next_page_url": null,
6
"page": 0,
7
"page_size": 50,
8
"previous_page_url": null,
9
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks?TaskQueueSid=WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&RoutingTarget=WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&TaskQueueName=task_queue_name&WorkflowName=workflow_name&WorkflowSid=WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&AssignmentStatus=pending%2Creserved&Priority=1&PageSize=50&Page=0"
10
},
11
"tasks": [
12
{
13
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"age": 25200,
15
"assignment_status": "pending",
16
"attributes": "{\"body\": \"hello\"}",
17
"date_created": "2014-05-14T14:26:54Z",
18
"date_updated": "2014-05-15T16:03:42Z",
19
"task_queue_entered_date": "2014-05-14T14:26:54Z",
20
"virtual_start_time": "2014-05-14T14:26:54Z",
21
"priority": 0,
22
"reason": "Test Reason",
23
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
24
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
26
"task_channel_unique_name": "task-channel",
27
"timeout": 60,
28
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
31
"workflow_friendly_name": "Test Workflow",
32
"task_queue_friendly_name": "Test Queue",
33
"ignore_capacity": false,
34
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
35
"addons": "{}",
36
"required_attention": 0,
37
"links": {
38
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
39
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
40
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
41
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
42
}
43
}
44
]
45
}
(information)

Info

Tasks are deleted 5 minutes after either they are canceled or completed. You can still query events that occurred for a Task via the Events API.

You may use the following operators in your EvaluateTaskAttributes:

  • Equality: ==, =
  • Inequality: !=
  • Greater than: >
  • Less than: <
  • Greater than or equal to: >=
  • Less than or equal to: <=
  • Use parentheses to indicate precedence of operations: ( )
  • Use brackets to indicate lists/arrays: [ ]
  • HAS, >- for determining whether the value of the Task attribute on the left-hand side of the expression contains the string on the right side of the comparison.
  • CONTAINS - for determining whether the value of the Task attribute on the left-hand side of the expression contains the value on the right side of the comparison.
  • IN, <- for determining whether the value of the Task attribute on the left-hand side of the expression is * contained in the list on the right-hand side.
  • NOT IN, <- for determining whether the value of the Task attribute on the left-hand side of the expression is * not contained in the list on the right-hand side.
  • AND if both the left and right subexpressions are true, resolves to true, otherwise false
  • OR - if one or both of the left or right subexpressions are true, resolves to true, otherwise false

By default, this will return the first 50 Tasks. Supply a PageSize parameter to fetch more than 50 Tasks. See paging for more information.


POST https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}

Property nameTypeRequiredPIIDescription
If-Matchstring

Optional

If provided, applies this mutation if (and only if) the ETag(link takes you to an external page) header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header(link takes you to an external page).

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the Task to update.

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

SidSID<WT>required

The SID of the Task resource to update.

Pattern: ^WT[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Attributesstring

Optional

The JSON string that describes the custom attributes of the task.


AssignmentStatusenum<string>

Optional

The new status of the task. Can be: canceled, to cancel a Task that is currently pending or reserved; wrapping, to move the Task to wrapup state; or completed, to move a Task to the completed state.

Possible values:
pendingreservedassignedcanceledcompletedwrapping

Reasonstring

Optional

The reason that the Task was canceled or completed. This parameter is required only if the Task is canceled or completed. Setting this value queues the task for deletion and logs the reason.


Priorityinteger

Optional

The Task's new priority value. When supplied, the Task takes on the specified priority unless it matches a Workflow Target with a Priority set. Value can be 0 to 2^31^ (2,147,483,647).


TaskChannelstring

Optional

When MultiTasking is enabled, specify the TaskChannel with the task to update. Can be the TaskChannel's SID or its unique_name, such as voice, sms, or default.


VirtualStartTimestring<date-time>

Optional

The task's new virtual start time value. When supplied, the Task takes on the specified virtual start time. Value can't be in the future or before the year of 1900.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateTask() {
11
const task = await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks("WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.update({
15
assignmentStatus: "canceled",
16
attributes: JSON.stringify({ type: "other" }),
17
reason: "waiting too long",
18
});
19
20
console.log(task.accountSid);
21
}
22
23
updateTask();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"age": 25200,
4
"assignment_status": "canceled",
5
"attributes": "{\"type\":\"other\"}",
6
"date_created": "2014-05-14T18:50:02Z",
7
"date_updated": "2014-05-15T07:26:06Z",
8
"task_queue_entered_date": "2014-05-14T18:50:02Z",
9
"virtual_start_time": "2023-08-02T12:34:56Z",
10
"priority": 0,
11
"reason": "waiting too long",
12
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"task_channel_unique_name": "task-channel",
16
"timeout": 60,
17
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
19
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20
"workflow_friendly_name": "Test Workflow",
21
"task_queue_friendly_name": "Test Queue",
22
"addons": "{}",
23
"ignore_capacity": false,
24
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"required_attention": 0,
26
"links": {
27
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
31
}
32
}

When a pending Task's attributes are updated, the Task will be re-driven through the Workflow identified by the WorkflowSid associated with the task. Depending on the Workflow's filters, TaskRouter may move the Task into a different TaskQueue. The age of the Task will remain the same. If the Task is moved to a new TaskQueue, its TaskQueue position relative to other tasks will be determined by its age and priority, as usual.

Check for version match before updating a TaskLink to code sample: Check for version match before updating a Task
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateTask() {
11
const task = await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks("WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.update({
15
assignmentStatus: "canceled",
16
ifMatch: "0",
17
reason: "waiting too long",
18
});
19
20
console.log(task.accountSid);
21
}
22
23
updateTask();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"age": 25200,
4
"assignment_status": "canceled",
5
"attributes": "{\"body\": \"hello\"}",
6
"date_created": "2014-05-14T18:50:02Z",
7
"date_updated": "2014-05-15T07:26:06Z",
8
"task_queue_entered_date": "2014-05-14T18:50:02Z",
9
"virtual_start_time": "2023-08-02T12:34:56Z",
10
"priority": 0,
11
"reason": "waiting too long",
12
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"task_queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"task_channel_unique_name": "task-channel",
16
"timeout": 60,
17
"url": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
19
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20
"workflow_friendly_name": "Test Workflow",
21
"task_queue_friendly_name": "Test Queue",
22
"addons": "{}",
23
"ignore_capacity": false,
24
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"required_attention": 0,
26
"links": {
27
"task_queue": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TaskQueues/WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"workflow": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Workflows/WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
29
"workspace": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"reservations": "https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Tasks/WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Reservations"
31
}
32
}

The previous version of Etag can be found in the client by accessing the following attribute:

client.httpClient.lastResponse.headers.etag


DELETE https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}

Deletes the Task identified by TaskSid. For all pending reservations associated with the deleted Task, these will also be deleted at task deletion time.

Property nameTypeRequiredPIIDescription
If-Matchstring

Optional

If provided, deletes this Task if (and only if) the ETag(link takes you to an external page) header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header(link takes you to an external page).

Property nameTypeRequiredPIIDescription
WorkspaceSidSID<WS>required

The SID of the Workspace with the Task to delete.

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

SidSID<WT>required

The SID of the Task resource to delete.

Pattern: ^WT[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteTask() {
11
await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks("WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.remove();
15
}
16
17
deleteTask();
Check for version match before deleting a TaskLink to code sample: Check for version match before deleting a Task
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteTask() {
11
await client.taskrouter.v1
12
.workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.tasks("WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.remove({ ifMatch: "0" });
15
}
16
17
deleteTask();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.