日本時間5月16日のContent Cloud Summitで、カスタムアプリにBox AI APIを活用する方法を紹介します。

詳細を表示

タスクの作成

ガイド タスク タスクの作成

タスクの作成

タスクを作成するには、タスクのactionと、タスクの追加先となるファイルを表すitemを指定してPOST /tasks APIを呼び出す必要があります。

cURL
curl -i -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(BoxTask.Action.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(f'Task message is {task.message} and it is due at {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' }
		*/
	});

タスクのアクション

Boxは現在、action値によって定義される、reviewcompleteという2種類のタスクをサポートしています。

タスクのタイプによって、タスクがなりうる解決状態と、ウェブアプリおよびモバイルアプリでユーザーに表示されるインターフェースが決まります。

タスクのアクション考えられる解決状態
reviewincomplete, approved, rejected
completeincomplete, complete

reviewタスクはincomplete状態で開始され、incompleteapproved、またはrejectedとしてマークすることができます。ユーザーインターフェースには、テキストボックスのほか、タスクを承認または拒否する1組のボタンが表示されます。

completeタスクはincomplete状態で開始され、incompleteまたはcompletedとしてマークすることができます。このタスクが完了としてマークされると、タスクの状態をそれ以上変更することはできなくなります。ユーザーインターフェースには、テキストボックスのほか、タスクを完了としてマークするためのボタンが表示されます。

完了のルール

ファイルに関連するタスクは、そのファイルの複数のコラボレータに割り当てることができます。また、タスクのcompletion_ruleを使用すると、タスクを完了する必要があるのはタスクが割り当てられているすべてのユーザー (all_assignees) か1人の担当者のみ (any_assignee) かを定義できます。