Skip to content

Instantly share code, notes, and snippets.

@allenmichael
Last active December 19, 2017 23:27
Show Gist options
  • Select an option

  • Save allenmichael/ba2136ab6abb5ff36313c3c7792ec038 to your computer and use it in GitHub Desktop.

Select an option

Save allenmichael/ba2136ab6abb5ff36313c3c7792ec038 to your computer and use it in GitHub Desktop.
'use strict';
const box = require('box-node-sdk');
const fs = require('fs');
let configFile = fs.readFileSync('config.json');
configFile = JSON.parse(configFile);
let session = box.getPreconfiguredInstance(configFile);
let serviceAccountClient = session.getAppAuthClient('user');
serviceAccountClient.enterprise.addAppUser("Jonathan", { "external_app_user_id": "jonathan" })
.then((user) => {
console.log(user);
})
.catch((err) => {
handleConflictError(err);
});
const handleConflictError = (err) => {
let userID;
if (err && err.response && err.response.body && err.response.body.context_info &&
err.response.body.context_info && err.response.body.context_info.conflicts) {
if (err.response.body.context_info.conflicts.length > 0) {
console.log(err.response.body.context_info);
userID = err.response.body.context_info.conflicts[0].id;
console.log("User already exists");
console.log(userID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment