Create Webhook for File

Create Webhook for File

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

curl -i -X POST "" \
     -H "Authorization: Bearer <ACCESS_TOKEN>" \
     -H "Content-Type: application/json" \
     -d '{
       "target": {
         "id": "21322",
         "type": "file"
       "address": "",
       "triggers": [
// Listen for preview events for a file
BoxFile file = new BoxFile(api, id);
BoxWebHook.Info webhookInfo = BoxWebHook.create(file, url, BoxWebHook.Trigger.FILE.PREVIEWED);
file = client.file(file_id='12345')
webhook = client.create_webhook(file, ['FILE.PREVIEWED'], '')
print('Webhook ID is {0} and the address is {1}'.format(, webhook.address))
client.webhooks.create(targetType: "file", targetId: "1234", triggers: [.fileDownloaded], address: "") { (result: Result<Webhook, BoxSDKError>) in
    guard case let .success(webhook) = result else {
        print("Error creating webhook")

    print("Created webhook \"\(\"")

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 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.