Tasks enable file-centric workflows in Box. User can create tasks on files and assign them to collaborators on Box.
- Get a Task's Information
- Get Tasks on a File
- Create a Task
- Update a Task
- Delete a Task
- Get Assignments for a Task
- Assign Task
- Get Task Assignment
- Update Task Assignment
- Remove Task Assignment
To get a task information call TasksManager.GetTaskAsync(string taskId)
with the ID of the task.
BoxTask task = await client.TasksManager.GetTaskAsync("11111");
Calling the FilesManager.GetFileTasks(string id, IEnumerable<string> fields = null)
method will retrieve all of the tasks for the given file.
BoxCollection<BoxTask> tasks = await client.FilesManager.FilesManager.GetFileTasks("11111");
To create a task, call TasksManager.CreateTaskAsync(BoxTaskCreateRequest taskCreateRequest)
with the
parameters of the task.
var taskParams = new BoxTaskCreateRequest()
{
Item = new BoxRequestEntity()
{
Type = BoxType.file,
Id = "11111"
},
Message = "Please review!"
};
BoxTask task = await client.TasksManager.CreateTaskAsync(taskParams);
To update a task, call
TasksManager.UpdateTaskAsync(BoxTaskUpdateRequest taskUpdateRequest)
.
var updates = new BoxTaskUpdateRequest()
{
Id = "22222",
Message = "Could you please review this?"
};
BoxTask updatedTask = await client.TasksManager.UpdateTaskAsync(updates);
To delete a task, call the TasksManager.DeleteTaskAsync(string taskId)
method with the ID of the task to be deleted.
await client.TasksManager.DeleteTaskAsync("11111");
To get a list of assignments for a task, which associate the task to users who
must complete it, call TasksManager.GetAssignmentsAsync(string taskId)
with the ID of the task.
BoxCollection<BoxTaskAssignment> assignments = await client.TasksManager
.GetAssignmentsAsync(taskId: "11111");
To assign a task to a user, call
TasksManager.CreateTaskAssignmentAsync(BoxTaskAssignmentRequest taskAssignmentRequest)
with the ID of the task to assign and either the ID or login email address of the
user to whom the task should be assigned.
// Assign task 11111 to user 22222
var assignmentParams = new BoxTaskAssignmentRequest()
{
Task = new BoxTaskRequest()
{
Id = "11111"
},
AssignTo = new BoxAssignmentRequest()
{
Id = "22222"
}
};
BoxTaskAssignment assignment = await client.TasksManager.CreateTaskAssignmentAsync(assignmentParams);
// Assign task 11111 to user with login [email protected]
var assignmentParams = new BoxTaskAssignmentRequest()
{
Task = new BoxTaskRequest()
{
Id = "11111"
},
AssignTo = new BoxAssignmentRequest()
{
Login = "[email protected]"
}
};
BoxTaskAssignment assignment = await client.TasksManager.CreateTaskAssignmentAsync(assignmentParams);
To retrieve information about a specific task assignment, call the
TasksManager.GetTaskAssignmentAsync(string taskAssignmentId)
method with the ID of the assignment to get.
BoxTaskAssignment assignment = await client.TasksManager.GetTaskAssignmentAsync("12345");
To update a task assignment, call the
TasksManager.UpdateTaskAssignmentAsync(BoxTaskAssignmentUpdateRequest taskAssignmentUpdateRequest)
method. This can be used to resolve or complete a task.
Updating the resolution state:
var requestParams = new BoxTaskAssignmentUpdateRequest()
{
Id = "12345",
ResolutionState = ResolutionStateType.approved
};
BoxTaskAssignment updatedAssignment = await client.TasksManager.UpdateTaskAssignmentAsync(requestParams);
Updating the message:
var requestParams = new BoxTaskAssignmentUpdateRequest()
{
Id = "12345",
Message = "Updated message"
};
BoxTaskAssignment updatedAssignment = await client.TasksManager.UpdateTaskAssignmentAsync(requestParams);
To delete a task assignment, effectively unassigning a user from the task, call the
TasksManager.DeleteTaskAssignmentAsync(string taskAssignmentId)
method with the ID of the assignment to remove.
await client.TasksManager.DeleteTaskAssignmentAsync("12345");