> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# Calling Node.js SDK functions and handling errors

## Calling Node.js SDK functions and handling errors

## Calling functions

Making API calls through the Node.js SDK requires calling defined functions in the API modules. Each of these functions corresponds to a group of endpoints that are used for specific feature areas related to the Docusign eSignature REST API.

Each specific REST endpoint typically has two or more Node.js SDK functions that can be used to call it. As an example, here are two functions that call the endpoint `'/v2.1/accounts/{accountId}/brands/{brandId}'`:

```text
    this.getBrand = function(accountId, brandId, optsOrCallback, callback)
    this.updateBrand = function(accountId, brandId, optsOrCallback, callback)
```

The difference between [getBrand](https://github.com/docusign/docusign-esign-node-client/blob/master/src/api/AccountsApi.js#L1593) and [updateBrand](https://github.com/docusign/docusign-esign-node-client/blob/master/src/api/AccountsApi.js#L3523) is the HTTP request method. The `getBrand` function makes a GET request to retrieve information for a specific `brandId`, while `updateBrand` makes a POST request to update the specific brand.

## Handling errors

Error handling is an important part of developing your software. Your code should handle both expected and unexpected errors.

The Node.js SDK provides an [DocusignAPIError](https://github.com/docusign/docusign-esign-node-client/blob/master/src/auth/errors/docusignapierror.js) function that is used for common scenarios where exceptions are thrown. It’s a best practice to catch this exception in your code and inspect the error `code` and `message` properties, which provide useful information to understand the cause of the error.

Common scenarios where the SDK throws a `DocusignAPIError` are:

* Invalid or expired access token.
* HTTP response status code 400 and above. These represent various [error messages](/docs/esign-rest-api/esign101/error-codes) that are identified by the HTTP layer. Such errors include not authorized (403) errors, which occur due to issues with authentication.
* Issues in deserialization of the response JSON. If the JSON sent back by the API cannot be properly deserialized into the Node.js objects that the SDK is expecting, a `DocusignAPIError` is thrown, and the "bad" JSON is returned in the `message` property of the exception.
* JWT issues with either the private RSA key pair or `userId`. Since the [requestJWTUserToken](https://github.com/docusign/docusign-esign-node-client/blob/master/src/ApiClient.js#L910) function for obtaining an OAuth token using JWT is included in the SDK, a `DocusignAPIError` is thrown if the RSA key or `userId` is missing or malformed.

[Troubleshooting for common errors](/docs/esign-rest-api/esign101/error-codes/troubleshooting-common-errors) has detailed information about causes and resolutions for specific errors.

### Obtaining the trace token for solving problems via Support

Every API response includes a GUID that can be used to trace it on the back end by Docusign [Support](https://support.docusign.com/). This GUID is called the *trace token*. The trace token enables Support staff to find the internal logs in the system related to the API request/response and to get additional information about it. This information may not be directly available to developers with or without the SDK.

To obtain the trace token, first create a callback function that will retain the trace token from the header of the HTTP response.

```text

function cb(error, data, response) {
    if (!error) {
        console.log(`Brand updated`);
        console.log(
          `Trace token: ${response.headers["x-docusign-tracetoken"]}.`);
    } else {
        // error...
        console.error (`\n\n${JSON.stringify(error,null,4)}\n\n`);
        process.exit(1);
    }
}
```

Pass this callback function as an argument when making your API call. The trace token will be logged to the console when the callback function is executed.

```text
accountsApi.updateBrand(accountId, brandId, cb)
```

**Note:** Some API calls do not return an error, but instead provide error information inside the body of the HTTP response. In this case, you will need to have your code check the data returned from the API to make sure the call was successful.