module:ApiClient

module:ApiClient

new module:ApiClient()

Source:

Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
application to use this class directly - the *Api and model classes provide the public API for the service. The
contents of this file should be regarded as internal but are documented for completeness.

Members

(static, readonly) CollectionFormatEnum :String

Source:
Properties:
Name Type Description
CSV String

Comma-separated values. Value: csv

SSV String

Space-separated values. Value: ssv

TSV String

Tab-separated values. Value: tsv

PIPES String

Pipe(|)-separated values. Value: pipes

MULTI String

Native array. Value: multi

Enumeration of collection format separator strategies.

Type:
  • String

(static) instance :module:ApiClient

Source:

The default API client implementation.

Type:

authentications :Array.<String>

Source:

The authentication methods to be included for all API calls.

Type:
  • Array.<String>

basePath :String

Source:
Default Value:
  • https://www.docusign.net/restapi

The base URL against which to resolve every API call's (relative) path.

Type:
  • String

cache :Boolean

Source:
Default Value:
  • true

If set to false an additional timestamp parameter is added to all API GET calls to
prevent browser caching

Type:
  • Boolean

defaultHeaders :Array.<String>

Source:
Default Value:
  • {}

The default HTTP headers to be included for all API calls.

Type:
  • Array.<String>

oAuthBasePath :String

Source:
Default Value:
  • https://www.docusign.net/restapi

The base URL against which to resolve every authentication API call's (relative) path.

Type:
  • String

timeout :Number

Source:
Default Value:
  • 60000

The default HTTP timeout for all API calls.

Type:
  • Number

Methods

(static) constructFromObject(data, obj)

Source:

Constructs a new map or array model from REST data.

Parameters:
Name Type Description
data Object | Array

The REST data.

obj Object | Array

The target object or array.

(static) convertToType(data, type)

Source:

Converts a value to the specified type.

Parameters:
Name Type Description
data String | Object

The data to convert, as a string or object.

type String | Array.<String> | Object.<String, Object> | function

The type to return. Pass a string for simple types
or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
all properties on data will be converted to this type.

Returns:

An instance of the specified type.

(static) parseDate(str) → {Date}

Source:

Parses an ISO-8601 string representation of a date value.

Parameters:
Name Type Description
str String

The date value as a string.

Returns:

The parsed date object.

Type
Date

addDefaultHeader()

Source:

Adds request headers to the API client. Useful for Authentication.

applyAuthToRequest(request, authNames)

Source:

Applies authentication headers to the request.

Parameters:
Name Type Description
request Object

The request object created by a superagent() call.

authNames Array.<String>

An array of authentication method names.

buildCollectionParam(param, collectionFormat) → {String|Array}

Source:

Builds a string representation of an array-type actual parameter, according to the given collection format.

Parameters:
Name Type Description
param Array

An array parameter.

collectionFormat module:ApiClient.CollectionFormatEnum

The array element separator strategy.

Returns:

A string representation of the supplied collection, using the specified delimiter. Returns
param as is if collectionFormat is multi.

Type
String | Array

buildUrl(path, pathParams) → {String}

Source:

Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
NOTE: query parameters are not handled here.

Parameters:
Name Type Description
path String

The path to append to the base URL.

pathParams Object

The parameter values to append.

Returns:

The encoded path with parameter values substituted.

Type
String

callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, callback) → {Object}

Source:

Invokes the REST service using the supplied settings and parameters.

Parameters:
Name Type Description
path String

The base URL to invoke.

httpMethod String

The HTTP method to use.

pathParams Object.<String, String>

A map of path parameters and their values.

queryParams Object.<String, Object>

A map of query parameters and their values.

headerParams Object.<String, Object>

A map of header parameters and their values.

formParams Object.<String, Object>

A map of form parameters and their values.

bodyParam Object

The value to pass as the request body.

authNames Array.<String>

An array of authentication type names.

contentTypes Array.<String>

An array of request MIME types.

accepts Array.<String>

An array of acceptable response MIME types.

returnType String | Array | ObjectFunction

The required type to return; can be a string for simple types or the
constructor for a complex type.

callback module:ApiClient~callApiCallback

The callback function. If this is left undefined, this method will return a promise instead.

Returns:

The SuperAgent request object if a callback is specified, else {Promise} A Promise object.

Type
Object

configureJWTAuthorizationFlow(privateKeyFilename, oAuthBasePath, clientId, userId, expiresIn, callback)

Source:
Deprecated:
  • since version 4.1.0 Configures the current instance of ApiClient with a fresh OAuth JWT access token from DocuSign
Parameters:
Name Type Description
privateKeyFilename

the filename of the RSA private key

oAuthBasePath

DocuSign OAuth base path (account-d.docusign.com for the developer sandbox
and account.docusign.com for the production platform)

clientId

DocuSign OAuth Client Id (AKA Integrator Key)

userId

DocuSign user Id to be impersonated (This is a UUID)

expiresIn

in seconds for the token time-to-live

callback

the callback function.

deserialize(response, returnType)

Source:

Deserializes an HTTP response body into a value of the specified type.

Parameters:
Name Type Description
response Object

A SuperAgent response object.

returnType String | Array.<String> | Object.<String, Object> | function

The type to return. Pass a string for simple types
or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
all properties on data will be converted to this type.

Returns:

A value of the specified type.

generateAccessToken(clientId, clientSecret, code)

Source:
Parameters:
Name Type Description
clientId

OAuth2 client ID: Identifies the client making the request.
Client applications may be scoped to a limited set of system access.

clientSecret

the secret key you generated when you set up the integration in DocuSign Admin console.

code

The authorization code that you received from the getAuthorizationUri callback.

Returns:

OAuthToken object.xx

getAuthorizationUri(clientId, scopes, redirectUri, responseType, state)

Source:

Helper method to configure the OAuth accessCode/implicit flow parameters

Parameters:
Name Type Description
clientId

OAuth2 client ID: Identifies the client making the request.
Client applications may be scoped to a limited set of system access.

scopes

the list of requested scopes.

redirectUri

this determines where to deliver the response containing the authorization code or access token.

responseType

determines the response type of the authorization request.

Note: these response types are mutually exclusive for a client application.
A public/native client application may only request a response type of "token";
a private/trusted client application may only request a response type of "code".

state

Allows for arbitrary state that may be useful to your application.
The value in this parameter will be round-tripped along with the response so you can make sure it didn't change.

getBasePath()

Source:

Gets the API endpoint base URL.

getJWTUri(clientId, redirectURI, oAuthBasePath) → {string}

Source:

Helper method to build the OAuth JWT grant uri (used once to get a user consent for impersonation)

Parameters:
Name Type Description
clientId

OAuth2 client ID

redirectURI

OAuth2 redirect uri

oAuthBasePath

DocuSign OAuth base path (account-d.docusign.com for the developer sandbox
and account.docusign.com for the production platform)

Returns:

the OAuth JWT grant uri as a String

Type
string

getOAuthBasePath()

Source:

Gets the authentication server endpoint base URL.

getUserInfo(accessToken)

Source:
Parameters:
Name Type Description
accessToken

the bearer token to use to authenticate for this call.

Returns:

OAuth UserInfo model

isFileParam(param) → {Boolean}

Source:

Checks whether the given parameter value represents file-like content.

Parameters:
Name Type Description
param

The parameter to check.

Returns:

true if param represents a file.

Type
Boolean

isJsonMime(contentType) → {Boolean}

Source:

Checks whether the given content type represents JSON.

JSON content type examples:

  • application/json
  • application/json; charset=UTF8
  • APPLICATION/JSON
Parameters:
Name Type Description
contentType String

The MIME content type to check.

Returns:

true if contentType represents JSON, otherwise false.

Type
Boolean

jsonPreferredMime(contentTypes) → {String}

Source:

Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.

Parameters:
Name Type Description
contentTypes Array.<String>
Returns:

The chosen content type, preferring JSON.

Type
String

normalizeParams(params) → {Object.<String, Object>}

Source:

Normalizes parameter values:

  • remove nils
  • keep files and arrays
  • format to string with `paramToString` for other cases
Parameters:
Name Type Description
params Object.<String, Object>

The parameters as object properties.

Returns:

normalized parameters.

Type
Object.<String, Object>

paramToString(param) → {String}

Source:

Returns a string representation for an actual parameter.

Parameters:
Name Type Description
param

The actual parameter.

Returns:

The string representation of param.

Type
String

setBasePath()

Source:

Sets the API endpoint base URL.

setOAuthBasePath()

Source:

Sets the authentication server endpoint base URL.

Type Definitions

callApiCallback(error, data, response)

Source:

(Optional)Callback function to receive the result of the operation. If none specified a Promise will be returned.

Parameters:
Name Type Description
error String

Error message, if any.

data

The data returned by the service call.

response String

The complete HTTP response.