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
(warning)
Warning
Pagination is not supported under this resource. Please avoid usage of the page query parameter.
Task Attributes
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:
_10
{
_10
"type": "call",
_10
"contact": "+15558675309",
_10
"customer-value": "gold",
_10
"task-reason": "support",
_10
"callSid": "CA42ed11..."
_10
}
Task Version
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.
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.
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.
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.
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.
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).
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.
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" }.
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.
Create a Task
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl
_13
// Download the helper library from https://www.twilio.com/docs/node/install
_13
// Find your Account SID and Auth Token at twilio.com/console
_13
// and set the environment variables. See http://twil.io/secure
Please contact us 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.
Fetch a Task resource
GET https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}
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.
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.
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.
Update a Task resource
POST https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}
If provided, applies this mutation if (and only if) the ETag header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header.
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.
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.
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).
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.
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 Task
Use the If-Match header to check Task Version
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl
_15
// Download the helper library from https://www.twilio.com/docs/node/install
_15
// Find your Account SID and Auth Token at twilio.com/console
_15
// and set the environment variables. See http://twil.io/secure
Deletes the Task identified by TaskSid. For all pending reservations associated with the deleted Task, these will also be deleted at task deletion time.
If provided, deletes this Task if (and only if) the ETag header of the Task matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header.