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

詳細を表示

Webhookを作成

post
https://api.box.com/2.0
/webhooks

Webhookを作成します。

リクエスト

bearer [ACCESS_TOKEN]
application/json

リクエスト本文

string本文内必須
"https://example.com/webhooks"

このWebhookによって通知されるURL

object本文内

Webhookをトリガーする項目

string本文内必須
"1231232"

Webhookをトリガーする項目のID

string本文内必須
"file"

Webhookをトリガーする項目のタイプ

次の値のいずれか1つ: file,folder

string array本文内必須
["FILE.UPLOADED"]

このWebhookがトリガーされるイベント名の配列

レスポンス

application/jsonWebhook

新しいWebhookオブジェクトを返します。

パラメータが正しくなかった場合は、エラーを返します。

アプリケーションにWebhookを管理する権限が付与されていない場合は、エラーを返します。

ターゲット項目が見つからなかった場合は、エラーを返します

同じターゲット、アプリケーション、ユーザーの組み合わせのWebhookがすでに存在する場合は、エラーを返します。

予期しないクライアントエラー。

post
Webhookを作成
このドキュメント内で一部のAPIを試せるようになりました。
ログイン

リクエストの例

cURL
curl -i -X POST "https://api.box.com/2.0/webhooks" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "target": {
         "id": "21322",
         "type": "file"
       },
       "address": "https://example.com/webhooks",
       "triggers": [
         "FILE.PREVIEWED"
       ]
     }'
.NET
var webhookParams = new BoxWebhookRequest()
{
    Target = new BoxRequestEntity()
    {
        Type = BoxType.file,
        Id = "22222"
    },
    Triggers = new List<string>()
    {
        "FILE.PREVIEWED"
    },
    Address = "https://example.com/webhook"
};
BoxWebhook webhook = await client.WebhooksManager.CreateWebhookAsync(webhookParams);
Java
// Listen for preview events for a file
BoxFile file = new BoxFile(api, id);
BoxWebHook.Info webhookInfo = BoxWebHook.create(file, url, BoxWebHook.Trigger.FILE.PREVIEWED);
Python
file = client.file(file_id='12345')
webhook = client.create_webhook(file, ['FILE.PREVIEWED'], 'https://example.com')
print(f'Webhook ID is {webhook.id} and the address is {webhook.address}')
Node
// Attach a webhook that sends a notification to https://example.com/webhook when
//   file 11111 is renamed or downloaded.
client.webhooks.create(
	'11111',
	client.itemTypes.FILE,
	'https://example.com/webhook',
	[
		client.webhooks.triggerTypes.FILE.RENAMED,
		client.webhooks.triggerTypes.FILE.DOWNLOADED
	])
	.then(webhook => {
		/* webhook -> {
			id: '12345',
			type: 'webhook',
			target: { id: '11111', type: 'file' },
			created_by: 
			{ type: 'user',
				id: '33333',
				name: 'Example User',
				login: 'user@example.com' },
			created_at: '2016-05-09T17:41:27-07:00',
			address: 'https://example.com/webhook',
			triggers: [ 'FILE.RENAMED', 'FILE.UPLOADED' ] }
		*/
	});
iOS
client.webhooks.create(targetType: "file", targetId: "1234", triggers: [.fileDownloaded], address: "www.testurl.com") { (result: Result<Webhook, BoxSDKError>) in
    guard case let .success(webhook) = result else {
        print("Error creating webhook")
        return
    }

    print("Created webhook \"\(webhook.id)\"")
}

レスポンスの例

{
  "id": "11446498",
  "type": "webhook",
  "address": "https://example.com/webhooks",
  "created_at": "2012-12-12T10:53:43-08:00",
  "created_by": {
    "id": "11446498",
    "type": "user",
    "login": "ceo@example.com",
    "name": "Aaron Levie"
  },
  "target": {
    "id": "1231232",
    "type": "file"
  },
  "triggers": [
    "FILE.UPLOADED"
  ]
}