Create a task

Create a task

To create a task, you will need to provide the POST /tasks API with the action for the task, as well as an item to represent the file to add the task to.

cURL
curl -X POST https://api.box.com/2.0/tasks \
     -H 'Authorization: Bearer <ACCESS_TOKEN>'
     -H 'Content-Type: application/json" '
     -d '{
       "item": {
         "id": "11446498",
         "type": "file"
       },
       "action": "review"
     }'
.NET
var taskParams = new BoxTaskCreateRequest()
{
    Item = new BoxRequestEntity()
    {
        Type = BoxType.file,
        Id = "11111"
    },
    Message = "Please review!"
};
BoxTask task = await client.TasksManager.CreateTaskAsync(taskParams);
Java
BoxFile file = new BoxFile(api, "id");
Date dueAt = new Date();
file.addTask("review", "Please review this file.", dueAt);
Python
message = 'Please review this'
due_at = "2014-04-03T11:09:43-07:00"
task = client.file(file_id='11111').create_task(message, due_at)
print('Task message is {0} and it is due at {1}'.format(task.message, task.due_at))
Node
var options = {
	message: 'Please review for publication!',
	due_at: '2014-04-03T11:09:43-07:00'
};
client.tasks.create('22222', options)
	.then(task => {
		/* task -> {
			type: 'task',
			id: '11111',
			item: 
			{ type: 'file',
				id: '22222',
				sequence_id: '0',
				etag: '0',
				sha1: '0bbd79a105c504f99573e3799756debba4c760cd',
				name: 'box-logo.png' },
			due_at: '2014-04-03T11:09:43-07:00',
			action: 'review',
			message: 'Please review for publication!',
			task_assignment_collection: { total_count: 0, entries: [] },
			is_completed: false,
			created_by: 
			{ type: 'user',
				id: '33333',
				name: 'Example User',
				login: 'user@example.com' },
			created_at: '2013-04-03T11:12:54-07:00' }
		*/
	});

Task actions

Box currently supports two types of tasks defined by the action value: review tasks and complete tasks.

The type of task determines the possible resolution states a task can be in and the interface shown to a user in the web and mobile apps.

Task actionPossible resolution states
reviewincomplete, approved, rejected
completeincomplete, complete

A review task starts out in an incomplete state and can be marked as incomplete, approved, or rejected. In the user interface a user is provided with a text box and an pair of buttons to approve or reject the task.

A complete task starts out in an incomplete state and can be marked incomplete or completed. Once a this task is marked completed, no further changes can be made to the task's state. In the user interface a user is provided with a text box and an button to mark the task as completed.

Completion rules

A task on a file can be assigned to more than one collaborator on the file, and a task has a completion_rule that can be used to define if all users who've been assigned the task (all_assignees) or only one assignee (any_assignee) need to complete the task.