Class: BoxClient

BoxClient(apiSession, config, requestManager)

new BoxClient(apiSession, config, requestManager)

The BoxClient can make API calls on behalf of a valid API Session. It is responsible for formatting the requests and handling the response. Its goal is to deliver sensible results to the user.
Parameters:
Name Type Description
apiSession APISession An initialized API Session, used to get/revoke tokens and handle unauthorized responses from the API.
config Config The SDK configuration options
requestManager APIRequestManager The API Request Manager
Source:

Members

(readonly) accessLevels :AccessLevel

Enum of valid values for setting different access levels. To be used when creating and editting shared links, upload emails, etc.
Type:
Source:

(readonly) collaborationRoles :CollaborationRole

Enum of valid collaboration roles
Type:
Properties:
Name Type Description
EDITOR CollaborationRole
VIEWER CollaborationRole
PREVIEWER CollaborationRole
UPLOADER CollaborationRole
PREVIEWER_UPLOADER CollaborationRole
VIEWER_UPLOADER CollaborationRole
CO_OWNER CollaborationRole
OWNER CollaborationRole
Source:

(constant) CURRENT_USER_ID :string

Type:
  • string
Source:

(readonly) itemTypes :ItemType

Enum of Box item types
Type:
Properties:
Name Type Description
FILE ItemType
FOLDER ItemType
Source:

Methods

asSelf() → {void}

Revoke the As-User context and return to making calls on behalf of the user who owns the client's access token.
Source:
Returns:
Type
void

asUser(userID) → {void}

Set up the As-User context, which is used by enterprise admins to impersonate their managed users and perform actions on their behalf.
Parameters:
Name Type Description
userID string The ID of the user to impersonate
Source:
Returns:
Type
void

buildSharedItemAuthHeader(url, passwordopt) → {string}

Build the 'BoxApi' Header used for authenticating access to a shared item
Parameters:
Name Type Attributes Description
url string The shared link url
password string <optional>
The shared link password
Source:
Returns:
A properly formatted 'BoxApi' header
Type
string

defaultResponseHandler(callback) → (nullable) {function}

Return a callback that properly handles a successful response code by passing the response body to the original callback. Any request error or unsuccessful response codes are propagated back to the callback as errors. This is the standard behavior of most endpoints.
Parameters:
Name Type Description
callback function The original callback given by the consumer
Source:
Returns:
A new callback that processes the response before passing it to the callback.
Type
function

del(path, paramsnullable, callback) → {void}

Makes DELETE request to Box API V2 endpoint
Parameters:
Name Type Attributes Description
path string path to a certain API endpoint (ex: /file)
params Object <nullable>
object containing parameters for the request, such as query strings and headers
callback function passed final API response or err if request failed
Source:
Returns:
Type
void

exchangeToken(scopes, resourceopt, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Exchange the client access token for one with lower scope
Parameters:
Name Type Attributes Description
scopes string | Array.<string> The scope(s) requested for the new token
resource string <optional>
The absolute URL of an API resource to scope the new token to
options Object <optional>
Optional parameters
Properties
Name Type Attributes Description
actor ActorParams <optional>
Optional actor parameters for creating annotator tokens with Token Auth client
sharedLink SharedLinkParams <optional>
Optional shared link parameters for creating tokens using shared links
callback function <optional>
Called with the new token
Source:
Returns:
A promise resolving to the exchanged token info
Type
Promise.<TokenInfo>

get(path, paramsnullable, callbackopt) → {void}

Makes GET request to Box API V2 endpoint
Parameters:
Name Type Attributes Description
path string path to a certain API endpoint (ex: /file)
params Object <nullable>
object containing parameters for the request, such as query strings and headers
callback function <optional>
passed final API response or err if request failed
Source:
Returns:
Type
void

options(path, paramsnullable, callback) → {void}

Makes an OPTIONS call to a Box API V2 endpoint
Parameters:
Name Type Attributes Description
path string Path to an API endpoint (e.g. /files/content)
params Object <nullable>
An optional object containing request parameters
callback function Called with API call results, or err if call failed
Source:
Returns:
Type
void

plug(name, plugin, optionsopt) → {void}

Add a SDK plugin. Warning: This will modify the box-client interface and can override existing properties.
Parameters:
Name Type Attributes Description
name string Plugin name. Will be accessible via client.
plugin function The SDK plugin to add
options Object <optional>
Plugin-specific options
Source:
Throws:
Will throw an error if plugin name matches an existing method on box-client
Returns:
Type
void

post(path, paramsnullable, callbackopt) → {void}

Makes POST request to Box API V2 endpoint
Parameters:
Name Type Attributes Description
path string path to a certain API endpoint (ex: /file)
params Object <nullable>
object containing parameters for the request, such as query strings and headers
callback function <optional>
passed final API response or err if request failed
Source:
Returns:
Type
void

put(path, paramsnullable, callback) → {void}

Makes PUT request to Box API V2 endpoint
Parameters:
Name Type Attributes Description
path string path to a certain API endpoint (ex: /file)
params Object <nullable>
object containing parameters for the request, such as query strings and headers
callback function passed final API response or err if request failed
Source:
Returns:
Type
void

revokeSharedContext() → {void}

Removes any current shared item context from API Session.
Source:
Returns:
Type
void

revokeTokens(callbackopt) → {Promise}

Revokes the client's access tokens. The client will no longer be tied to a user and will be unable to make calls to the API, rendering it effectively useless.
Parameters:
Name Type Attributes Description
callback function <optional>
Called after revoking, with an error if one existed
Source:
Returns:
A promise resolving when the client's access token is revoked
Type
Promise

setCustomHeader(header, value) → {void}

Set a custom header. A custom header is applied to every request for the life of the client. To remove a header, set it's value to null.
Parameters:
Name Type Description
header string The name of the custom header to set.
value * The value of the custom header. Set to null to remove the given header.
Source:
Returns:
Type
void

setIPs(ips) → {void}

Sets the list of requesting IP addresses for the X-Forwarded-For header. Used to give the API better information for uploads, rate-limiting, etc.
Parameters:
Name Type Description
ips Array.<string> Array of IP Addresses
Source:
Returns:
Type
void

setSharedContext(url, passwordnullable) → {void}

Sets the shared item context on the API Session. Overwrites any current context.
Parameters:
Name Type Attributes Description
url string The shared link url
password string <nullable>
The shared link password, null if no password exists.
Source:
Returns:
Type
void

upload(path, paramsnullable, formDatanullable, callback) → {void}

Makes a POST call to a Box API V2 upload endpoint
Parameters:
Name Type Attributes Description
path string path to an upload API endpoint
params Object <nullable>
an optional object containing request parameters
formData Object <nullable>
multipart form data to include in the upload request {@see https://github.com/mikeal/request#multipartform-data-multipart-form-uploads}
callback function called with API call results, or an error if the call failed
Source:
Returns:
Type
void

wrapWithDefaultHandler(method) → {function}

Wrap a client method with the default handler for both callback and promise styles
Parameters:
Name Type Description
method function The client method (e.g. client.get)
Source:
Returns:
The wrapped method
Type
function