Connect to Box API with Google Apps Script

You can use the OAuth2 library with Google Apps script to connect to the Box API. The Box API is available to all users and provide full access (read and write) to your Box account.

To get started, create a new Box application at and set the redirect_uri to your Google Apps Script project. Next include the OAuth2 library in your Google Script and call authorizeBox() from the Run menu to authorize the connection between your Google Account and Box account.

The getFolderList method will logs a list of all folders that are in the root folder of your Box account.

// Written by Amit Agarwal

// Step 1.
function authorizeBox() {
  var service = getBoxService_();
  if (!service.hasAccess()) {
    var authorizationUrl = service.getAuthorizationUrl();
    Logger.log('Open the following URL to authorize: %s',
  } else {
    Logger.log('Your account is already authorized');

// Step 2.
function getFoldersList() {
  var response = UrlFetchApp.fetch(',type', {
    headers: {
      'Authorization': 'Bearer ' + getBoxService_().getAccessToken()
  var result = JSON.parse(response.getContentText());
  var items = result.entries;
  var folders = [];
  for (var i=0; i