Class: BoxSDKNode

BoxSDKNode(params)

A backend NodeJS SDK to interact with the Box V2 API. This is the single entry point for all SDK consumer interactions. This is the only file that a 3rd party app should require. All other components are private and reached out to via this component. 1. Provides getters to spawn client instances for users to interact with the Box API. 2. Provides manual capability to acquire tokens via token grant endpoints. However, it is recommended to use clients to do this for you. 3. Emits notification events about relevant request/response events. Useful for logging Box API interactions. Notification events: request retries, exceeding max retries, permanent failures.

Constructor

new BoxSDKNode(params)

Parameters:
Name Type Description
params UserConfigurationOptions User settings used to initialize and customize the SDK
Source:

Members

(static) accessLevels

Expose the BoxClient property enumerations to the SDK as a whole. This allows the consumer to access and use these values from anywhere in their application (like a helper) by requiring the SDK, instead of needing to pass the client.
Source:

(static) validateWebhookMessage

Expose Webhooks.validateMessage() to the SDK as a whole. This allows the consumer to call BoxSDK.validateWebhookMessage() by just requiring the SDK, instead of needing to create a client (which is not needed to validate messages).
Source:

accessLevels

Expose the BoxClient property enumerations to the SDK as a whole. This allows the consumer to access and use these values from anywhere in their application (like a helper) by requiring the SDK, instead of needing to pass the client.
Source:

accessLevels

Expose the BoxClient property enumerations to the SDK as a whole. This allows the consumer to access and use these values from anywhere in their application (like a helper) by requiring the SDK, instead of needing to pass the client.
Source:

validateWebhookMessage

Expose Webhooks.validateMessage() to the SDK as a whole. This allows the consumer to call BoxSDK.validateWebhookMessage() by just requiring the SDK, instead of needing to create a client (which is not needed to validate messages).
Source:

Methods

(static) getBasicClient(accessToken) → {BoxClient}

Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user. A basic session has no access to a user's refresh token. Because of this, once the session's tokens expire the client cannot recover and a new session will need to be generated.
Parameters:
Name Type Description
accessToken string A user's Box API access token
Source:
Returns:
Returns a new Box Client paired to a new BasicAPISession
Type
BoxClient

(static) getBasicClient(accessToken) → {BoxClient}

Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user. A basic session has no access to a user's refresh token. Because of this, once the session's tokens expire the client cannot recover and a new session will need to be generated.
Parameters:
Name Type Description
accessToken string A user's Box API access token
Source:
Returns:
Returns a new Box Client paired to a new BasicAPISession
Type
BoxClient

(static) getPreconfiguredInstance(appConfig) → {BoxSDKNode}

Gets the BoxSDKNode instance by passing boxAppSettings json downloaded from the developer console.
Parameters:
Name Type Description
appConfig Object boxAppSettings object retrieved from Dev Console.
Source:
Returns:
an instance that has been preconfigured with the values from the Dev Console
Type
BoxSDKNode

(static) getPreconfiguredInstance(appConfig) → {BoxSDKNode}

Gets the BoxSDKNode instance by passing boxAppSettings json downloaded from the developer console.
Parameters:
Name Type Description
appConfig Object boxAppSettings object retrieved from Dev Console.
Source:
Returns:
an instance that has been preconfigured with the values from the Dev Console
Type
BoxSDKNode

configure(params) → {void}

Updates the SDK configuration with new parameters.
Parameters:
Name Type Description
params UserConfigurationOptions User settings
Source:
Returns:
Type
void

configure(params) → {void}

Updates the SDK configuration with new parameters.
Parameters:
Name Type Description
params UserConfigurationOptions User settings
Source:
Returns:
Type
void

getAnonymousClient() → {BoxClient}

Returns a Box Client configured to use Client Credentials Grant for a service account. Requires enterprise ID to be set when configuring SDK instance.
Source:
Returns:
Returns a new Box Client paired to a AnonymousAPISession. All Anonymous API Sessions share the same tokens, which allows them to refresh them efficiently and reduce load on both the application and the API.
Type
BoxClient

getAnonymousClient() → {BoxClient}

Returns a Box Client configured to use Client Credentials Grant for a service account. Requires enterprise ID to be set when configuring SDK instance.
Source:
Returns:
Returns a new Box Client paired to a AnonymousAPISession. All Anonymous API Sessions share the same tokens, which allows them to refresh them efficiently and reduce load on both the application and the API.
Type
BoxClient

getAppAuthClient(type, idopt, tokenStoreopt) → {BoxClient}

Create a new client using App Auth for the given entity. This allows either managing App Users (as the enterprise) or performing operations as the App Users or Managed Users themselves (as a user).
Parameters:
Name Type Attributes Description
type string The type of entity to operate as, "enterprise" or "user"
id string <optional>
(Optional) The Box ID of the entity to operate as
tokenStore TokenStore <optional>
(Optional) the token store to use for caching tokens
Source:
Returns:
A new client authorized as the app user or enterprise
Type
BoxClient

getAppAuthClient(type, idopt, tokenStoreopt) → {BoxClient}

Create a new client using App Auth for the given entity. This allows either managing App Users (as the enterprise) or performing operations as the App Users or Managed Users themselves (as a user).
Parameters:
Name Type Attributes Description
type string The type of entity to operate as, "enterprise" or "user"
id string <optional>
(Optional) The Box ID of the entity to operate as
tokenStore TokenStore <optional>
(Optional) the token store to use for caching tokens
Source:
Returns:
A new client authorized as the app user or enterprise
Type
BoxClient

getAppUserTokens(userID, optionsopt, callbackopt) → {Promise.<TokentInfo>}

Gets tokens for App Users via a JWT grant
Parameters:
Name Type Attributes Description
userID string The ID of the App User to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
Passed the tokens if successful
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokentInfo>

getAppUserTokens(userID, optionsopt, callbackopt) → {Promise.<TokentInfo>}

Gets tokens for App Users via a JWT grant
Parameters:
Name Type Attributes Description
userID string The ID of the App User to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
Passed the tokens if successful
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokentInfo>

getAuthorizeURL(params) → {string}

Generate the URL for the authorize page to send users to for the first leg of the OAuth2 flow.
Parameters:
Name Type Description
params Object The OAuth2 parameters
Source:
Returns:
The authorize page URL
Type
string

getAuthorizeURL(params) → {string}

Generate the URL for the authorize page to send users to for the first leg of the OAuth2 flow.
Parameters:
Name Type Description
params Object The OAuth2 parameters
Source:
Returns:
The authorize page URL
Type
string

getBasicClient(accessToken) → {BoxClient}

Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user. A basic session has no access to a user's refresh token. Because of this, once the session's tokens expire the client cannot recover and a new session will need to be generated.
Parameters:
Name Type Description
accessToken string A user's Box API access token
Source:
Returns:
Returns a new Box Client paired to a new BasicAPISession
Type
BoxClient

getBasicClient(accessToken) → {BoxClient}

Returns a Box Client with a Basic API Session. The client is able to make requests on behalf of a user. A basic session has no access to a user's refresh token. Because of this, once the session's tokens expire the client cannot recover and a new session will need to be generated.
Parameters:
Name Type Description
accessToken string A user's Box API access token
Source:
Returns:
Returns a new Box Client paired to a new BasicAPISession
Type
BoxClient

getCCGClientForUser(userId) → {BoxClient}

Returns a Box Client configured to use Client Credentials Grant for a specified user.
Parameters:
Name Type Description
userId the user ID to use when getting the access token
Source:
Returns:
Returns a new Box Client paired to a AnonymousAPISession. All Anonymous API Sessions share the same tokens, which allows them to refresh them efficiently and reduce load on both the application and the API.
Type
BoxClient

getCCGClientForUser(userId) → {BoxClient}

Returns a Box Client configured to use Client Credentials Grant for a specified user.
Parameters:
Name Type Description
userId the user ID to use when getting the access token
Source:
Returns:
Returns a new Box Client paired to a AnonymousAPISession. All Anonymous API Sessions share the same tokens, which allows them to refresh them efficiently and reduce load on both the application and the API.
Type
BoxClient

getEnterpriseAppAuthTokens(enterpriseID, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Gets tokens for enterprise administration of app users
Parameters:
Name Type Attributes Description
enterpriseID string The ID of the enterprise to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
Passed the tokens if successful
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getEnterpriseAppAuthTokens(enterpriseID, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Gets tokens for enterprise administration of app users
Parameters:
Name Type Attributes Description
enterpriseID string The ID of the enterprise to generate a token for
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
Passed the tokens if successful
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getPersistentClient(tokenInfo, tokenStoreopt) → {BoxClient}

Returns a Box Client with a persistent API session. A persistent API session helps manage the user's tokens, and can refresh them automatically if the access token expires. If a central data-store is given, the session can read & write tokens to it. NOTE: If tokenInfo or tokenStore are formatted incorrectly, this method will throw an error. If you haven't explicitly created either of these objects or are otherwise not completly confident in their validity, you should wrap your call to getPersistentClient in a try-catch to handle any potential errors.
Parameters:
Name Type Attributes Description
tokenInfo TokenInfo A tokenInfo object to use for authentication
tokenStore TokenStore <optional>
An optional token store for reading/writing tokens to session
Source:
Returns:
Returns a new Box Client paired to a new PersistentAPISession
Type
BoxClient

getPersistentClient(tokenInfo, tokenStoreopt) → {BoxClient}

Returns a Box Client with a persistent API session. A persistent API session helps manage the user's tokens, and can refresh them automatically if the access token expires. If a central data-store is given, the session can read & write tokens to it. NOTE: If tokenInfo or tokenStore are formatted incorrectly, this method will throw an error. If you haven't explicitly created either of these objects or are otherwise not completly confident in their validity, you should wrap your call to getPersistentClient in a try-catch to handle any potential errors.
Parameters:
Name Type Attributes Description
tokenInfo TokenInfo A tokenInfo object to use for authentication
tokenStore TokenStore <optional>
An optional token store for reading/writing tokens to session
Source:
Returns:
Returns a new Box Client paired to a new PersistentAPISession
Type
BoxClient

getTokensAuthorizationCodeGrant(authorizationCode, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Acquires token info using an authorization code
Parameters:
Name Type Attributes Description
authorizationCode string authorization code issued by Box
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
passed a TokenInfo object if tokens were granted successfully
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensAuthorizationCodeGrant(authorizationCode, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Acquires token info using an authorization code
Parameters:
Name Type Attributes Description
authorizationCode string authorization code issued by Box
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
passed a TokenInfo object if tokens were granted successfully
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensRefreshGrant(refreshToken, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Refreshes the access and refresh tokens for a given refresh token.
Parameters:
Name Type Attributes Description
refreshToken string A valid OAuth refresh token
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
passed a TokenInfo object if tokens were granted successfully
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

getTokensRefreshGrant(refreshToken, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Refreshes the access and refresh tokens for a given refresh token.
Parameters:
Name Type Attributes Description
refreshToken string A valid OAuth refresh token
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
passed a TokenInfo object if tokens were granted successfully
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

revokeTokens(token, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Revokes a token pair associated with a given access or refresh token.
Parameters:
Name Type Attributes Description
token string A valid access or refresh token to revoke
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
If err, revoke failed. Otherwise, revoke succeeded.
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>

revokeTokens(token, optionsopt, callbackopt) → {Promise.<TokenInfo>}

Revokes a token pair associated with a given access or refresh token.
Parameters:
Name Type Attributes Description
token string A valid access or refresh token to revoke
options TokenRequestOptions <optional>
Sets optional behavior for the token grant, null for default behavior
callback function <optional>
If err, revoke failed. Otherwise, revoke succeeded.
Source:
Returns:
Promise resolving to the token info
Type
Promise.<TokenInfo>