Skip to content

Instantly share code, notes, and snippets.

@allenmichael
Last active September 18, 2017 21:53
Show Gist options
  • Select an option

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

Select an option

Save allenmichael/e71bc5e2aff1abfe15848be8745a2222 to your computer and use it in GitHub Desktop.
Authenticate Box Service Account and list the Service Account's info.
'use strict';
// Require the Box SDK and the fs module
const box = require('box-node-sdk');
const fs = require('fs');
// Read and parse the automatically created Box configuration file.
let configFile = fs.readFileSync('config.json');
configFile = JSON.parse(configFile);
// Initialize the SDK with the Box configuration file and create a client that uses the Service Account.
let session = box.getPreconfiguredInstance(configFile);
let serviceAccountClient = session.getAppAuthClient('enterprise');
// Use the users.get method to retrieve current user's information by passing 'me' as the ID.
// Since this client uses the Service Account, this will return the Service Account's information.
serviceAccountClient.users.get('me', null)
.then((serviceAccountUser) => {
// Log the Service Account's login value which should contain "AutomationUser".
// For example, [email protected]
console.log(serviceAccountUser.login)
})
.catch((err) => {
// Log any errors for debugging
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment