Skip to content

Latest commit

 

History

History
210 lines (159 loc) · 9.48 KB

task.md

File metadata and controls

210 lines (159 loc) · 9.48 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 object, first call client.task(task_id) to construct the appropriate Task object, and then calling task.get(*, fields=None, headers=None, **kwargs) will return the Task object populated with data from the API, leaving the original object unmodified.

task = client.task(task_id='12345').get()
print(f'Task ID is {task.id} and the type is {task.type}')

List Tasks on File

To retrieve all tasks on a file, call [file.get_tasks(fields=None)]['get_tasks'] will return a BoxObjectCollection that allows you to iterate over the Task objects in the collection.

tasks = client.file(file_id='11111').get_tasks()
for task in tasks:
    print(f'Task ID is {task.id} and the type is {task.type}')

Add Task to File

To create a single task for a single user on a single file, call file.create_task(message=None, due_at=None) will return a newly created Task object populated with data from the API.

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(f'Task message is {task.message} and it is due at {task.due_at}')

Update Task Info

To update a task object, first call task.update_info(data=task_update) with a dict of properties to update on the task. This method returns a newly updated Task object, leaving the original object unmodified.

task_update = {'message': 'New Message', 'due_at': '2014-04-03T11:09:43-10:00'}
updated_task = client.task(task_id='12345').update_info(data=task_update)
print(f'New task message is {updated_task.message} and the new due time is {updated_task.due_at}')

Delete a Task

To delete a task, first call client.task(task_id) to construct the appropriate task object, and then call task.delete(). This method returns True to indicate that the deleteion was successful.

client.client.task('12345').delete()
print('The task was successfully delete!')

Assign a Task

To assign a task object, first call client.task(task_id) to construct the appropriate task object, then call task.assign(user) will return an Task Assignment object, populated with data from the API.

user = client.user(user_id='11111')
assignment = client.task(task_id='12345').assign(user)
print(f'Assignment ID is {assignment.id} and is assigned to user {assignment.assigned_to.name}')

Assign a Task with User Login

To assign a task object with a user login, first call task.assign_with_login(login) with a unicode value for user login. This method will return a TaskAssignment object, populated with data from the API.

assignment = client.task(task_id='12345').assign_with_login('[email protected]')
print(f'Assignment ID is {assignment.id} and the assignee is {assignment.assigned_to.login}')

List Task Assignments

To retrieve all assignments for an enterprise, first call client.task(task_id) to construct the appropriate task object. Then call 'task.get_assignments(fields=None)'. This method returns a BoxObjectCollection that allows you to iterate over the 'TaskAssignment' objects in the collection.

assignments = client.task(task_id='12345').get_assignments()
for assignment in assignments:
    print(f'Assignment ID is {assignment.id} and the assignee is {assignment.assigned_to.login}')

Get Information about Task Assignment

To get a task assignment object, first call client.task_assignment(assignment_id) to construct the appropriate TaskAssignment object, and then calling 'task_assignment.get(*, fields=None, headers=None, **kwargs)' will return the [TaskAssignment][task_assignment] object populated with data from the API.

assignment= client.task_assignment('12345').get()
print(f'Assignment ID is {assignment.id} and assignment type is {assignment.type}')

Update Task Assignment

To update a task assignment object, call assignment.update_info(data=updated_task) with a dict of properties to update on a task assignment. This method returns a newly update TaskAssignment object, leaving the original object unmodified.

from boxsdk.object.task_assignment import ResolutionState
updated_task = {'resolution_state': ResolutionState.APPROVED}
updated_assignment = client.task_assignment(assignment_id='12345').update_info(data=updated_task)
print(f'Assignment ID is {updated_assignment.id} and resolution state is {updated_assignment.resolution_state}')
updated_task = {'message': 'new message'}
updated_assignment = client.task_assignment(assignment_id='12345').update_info(data=updated_task)
print(f'Assignment ID is {updated_assignment.id} and message is {updated_task.message}')

Delete Task Assignment

To delete a task assignment, call task_assignment.delete(). This method returns True to indicate that the deletion was successful.

client.task_assignment(assignment_id='12345').delete()
print('The task assignment was successfully delete!')