Create Webhook for Folder

Create Webhook for Folder

To attach a webhook to an folder, call the Create webhook endpoint with the type of folder, the ID of the folder, a URL to send webhook notifications to, and a list of triggers that will cause the webhook to activate.

cURL
curl -X POST https://api.box.com/2.0/webhooks \
     -H 'Authorization: Bearer <ACCESS_TOKEN>'
     -H 'Content-Type: application/json" '
     -d '{
       "target": {
         "id": "234234", 
         "type": "folder"
       }, 
       "address": "https://example.com/webhooks",
       "triggers": [
         "FILE.UPLOADED"
       ]
     }'
.NET
var webhookParams = new BoxWebhookRequest()
{
    Target = new BoxRequestEntity()
    {
        Type = BoxType.folder,
        Id = "22222"
    },
    Triggers = new List<string>()
    {
        "FILE.UPLOADED",
        "FILE.DOWNLOADED"
    },
    Address = "https://example.com/webhook
};
BoxWebhook webhook = await client.WebhooksManager.CreateWebhookAsync(webhookParams);
Java
// Listen for file upload events in the specified folder
BoxFolder folder = new BoxFolder(api, id);
BoxWebHook.Info webhookInfo = BoxWebHook.create(folder, url, BoxWebHook.Trigger.FILE_UPLOADED);
Python
folder = client.folder(folder_id='12345')
webhook = client.create_webhook(folder, ['FILE.UPLOADED', 'FILE.PREVIEWED'], 'https://example.com')
print('Webhook ID is {0} and the address is {1}'.format(webhook.id, webhook.address))
Node
// Attach a webhook that sends a notification to https://example.com/webhook when
//   files are uploaded or downloaded within folder 22222.
client.webhooks.create(
	'22222',
	client.itemTypes.FOLDER,
	'https://example.com/webhook',
	[
		client.webhooks.triggerTypes.FILE.UPLOADED,
		client.webhooks.triggerTypes.FILE.DOWNLOADED
	])
	.then(webhook => {
		/* webhook -> {
			id: '1234',
			type: 'webhook',
			target: { id: '22222', type: 'folder' },
			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.DOWNLOADED', 'FILE.UPLOADED' ] }
		*/
	});

This API requires the application to have the "Manage webhooks" scope enabled.

The address for the webhook needs to be a HTTPS URL.

Webhook address

The notification URL specified in the address parameter must be a valid HTTPS URL that you specify when you create a webhook. Every time one of the triggers is activated, this URL will be called.

The notification URL must use the standard HTTPS port, 443 and should be the should return an HTTP status in the range of 200 to 299 within 30 seconds of receiving the webhook payload.

Webhook triggers

The triggers are a list of strings that specify the events that will cause the webhook to be triggered. For example, if you want the webhook to be triggered when a user uploads a file you'd pass in the FILE.UPLOADED trigger name.

A list of available triggers is available in the in this guide.