Skip to content

Latest commit

 

History

History
195 lines (157 loc) · 5.32 KB

tasks.md

File metadata and controls

195 lines (157 loc) · 5.32 KB

Tasks

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

To get a task information call TasksManager.GetTaskAsync(string taskId) with the ID of the task.

BoxTask task = await client.TasksManager.GetTaskAsync("11111");

Get Tasks on a File

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");

Create a Task

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);

Update a Task

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);

Delete a Task

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");

Get Assignments for a Task

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");

Assign Task

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);

Get Task Assignment

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");

Update Task Assignment

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);

Remove Task Assignment

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");