Created
September 11, 2018 18:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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