Box Developer Documentation

Join BoxWorks 2024 to discover what's possible with content and AI!

Register now!

Assign a task to a user

Assign a task to a user

To assign a task to a user you will need to provide the POST /task_assignments API with the id of the task and the user's details. For the user an application can either use the user id or the user's login email, which Box refers to as their login.

cURL
curl -i -X POST "https://api.box.com/2.0/task_assignments" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "task": {
         "id": "11446498",
         "type": "task"
       },
       "assign_to": {
         "id": "4823213"
       }
     }'
TypeScript Gen
await client.taskAssignments.createTaskAssignment({
  task: new CreateTaskAssignmentRequestBodyTaskField({
    type: 'task' as CreateTaskAssignmentRequestBodyTaskTypeField,
    id: task.id!,
  }),
  assignTo: {
    id: currentUser.id,
  } satisfies CreateTaskAssignmentRequestBodyAssignToField,
} satisfies CreateTaskAssignmentRequestBody);
Python Gen
client.task_assignments.create_task_assignment(
    CreateTaskAssignmentTask(
        type=CreateTaskAssignmentTaskTypeField.TASK.value, id=task.id
    ),
    CreateTaskAssignmentAssignTo(id=current_user.id),
)
.NET Gen
await client.TaskAssignments.CreateTaskAssignmentAsync(requestBody: new CreateTaskAssignmentRequestBody(task: new CreateTaskAssignmentRequestBodyTaskField(type: CreateTaskAssignmentRequestBodyTaskTypeField.Task, id: NullableUtils.Unwrap(task.Id)), assignTo: new CreateTaskAssignmentRequestBodyAssignToField() { Id = currentUser.Id }));
Swift Gen (Beta)
try await client.taskAssignments.createTaskAssignment(requestBody: CreateTaskAssignmentRequestBody(task: CreateTaskAssignmentRequestBodyTaskField(type: CreateTaskAssignmentRequestBodyTaskTypeField.task, id: task.id!), assignTo: CreateTaskAssignmentRequestBodyAssignToField(id: currentUser.id)))
Java
BoxUser user = new BoxUser(api, "user-id")
BoxTask task = new BoxTask(api, "id");
task.addAssignment(user);
Python
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}')
.NET
// 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);
Node
// Assign task 11111 to user 22222
var taskID = '11111';
var userID = '22222';
client.tasks.assignByUserID(taskID, userID)
	.then(assignment => {
		/* assignment -> {
			type: 'task_assignment',
			id: '12345',
			item: 
			{ type: 'file',
				id: '33333',
				sequence_id: '0',
				etag: '0',
				sha1: '7840095ee096ee8297676a138d4e316eabb3ec96',
				name: 'script.js' },
			assigned_to: 
			{ type: 'user',
				id: '22222',
				name: 'Sample Assignee',
				login: 'assignee@exmaple.com' },
			message: null,
			completed_at: null,
			assigned_at: '2013-05-10T11:43:41-07:00',
			reminded_at: null,
			resolution_state: 'incomplete',
			assigned_by: 
			{ type: 'user',
				id: '33333',
				name: 'Example User',
				login: 'user@example.com' } }
		*/
	});

Notifications

When creating a task an email notification is sent to the user who the task is assigned to.

Permissions

Both the user assigning the task and the user the task is being assigned to needs to be a collaborator on the file.