Last active
December 19, 2017 23:27
-
-
Save allenmichael/ba2136ab6abb5ff36313c3c7792ec038 to your computer and use it in GitHub Desktop.
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'; | |
| 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