Skip to content

Instantly share code, notes, and snippets.

@jcleblanc
Created September 11, 2018 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcleblanc/655d986425fc714d78926d7d86ff36f1 to your computer and use it in GitHub Desktop.
Save jcleblanc/655d986425fc714d78926d7d86ff36f1 to your computer and use it in GitHub Desktop.
Create a webhook on a folder in Box to listen for file upload events
'use strict';
// Initialize packages
const util = require('util'); // Deep inspection of objects
const boxSDK = require('box-node-sdk'); // Box SDK
const fs = require('fs'); // File system for config
// Fetch config file for instantiating SDK instance
// SAVE YOUR OWN APP CONFIG FILE TO config.json
const configJSON = JSON.parse(fs.readFileSync('config.json'));
// Instantiate instance of SDK using generated JSON config
const sdk = boxSDK.getPreconfiguredInstance(configJSON);
// Create service account client
const client = sdk.getAppAuthClient('enterprise');
/****************************************************************
* Create Webhook
****************************************************************/
// CREATE WEBHOOK
const folderId = '33552452293';
const notificationURL = 'https://www.mysite.com/response';
client.webhooks.create(
folderId,
client.itemTypes.FOLDER,
notificationURL,
[
client.webhooks.triggerTypes.FILE.UPLOADED
]
).then(webhook => {
console.log(util.inspect(webhook, false, null));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment