Overview

Docusign Library

What is it?

A C# client library to communicate with Docusign's REST API

Project Solution

DocusignLib (client library)

DocusignLibUnitTests (client library unit tests)

DocusignMvcDemo (demonstration of client library use in a web application)

DocusignLib Project

Design

All REST API actions filter through the Authorizer object. This object handles API authorization, login account authorization, REST communication transactions, and type casting responses to either a strongly typed result, a JSON object, or a String for parsing. Strongly typed reponse objects are returned via a Manager class. Each manager is responsible for the communicating with the authorizer and providing the casting information.

Wiring

class Authorizer {
    ...

    public T ExecuteRequest<T>(RestRequest request) where T : new()
    {
        AuthorizeRequest(request);
        IRestResponse<T> response = GetClient().Execute<T>(request);
        return response.Data;
    }

    public T ExecuteRequest<T>(RestRequest request, String username) where T : new()
    {
        ChangeClientAccount(username);
        return ExecuteRequest<T>(request);
    }

    public String ExecuteRequestToString(RestRequest request, String username)
    {
        ChangeClientAccount(username);
        AuthorizeRequest(request);
        IRestResponse response = _client.Execute(request);

        return response.Content;
    }

    public JObject ExecuteRequestToJObject(RestRequest request, String username)
    {
        return JObject.Parse(ExecuteRequestToString(request, username));
    }

    ...
}

To use the client library

  1. Create a Credentials object instance with your company API credentials (demo credentials included in source).
  2. Create a Authorizer object instance providing it with the Credentials object, REST API server name, and API version.
  3. The Authorizer object can now be passed around to all the REST actions that you want to preform.

Security

Credentials credentials = new Credentials("<api_username", "<api_password>", "<api_integrator_key>");
Authorizer authorizer = new Authorizer(credentials, "<rest_server_uri>", "<api_version>");

Action

TemplatesContainer container = TemplateManger.GetTemplates(authorizer, "<requesting_username>", "<folder_name>");
foreach(EnvelopeTemplate template in container.evelopeTemplates) {
    Console.Write("Template Id: " + template.TemplateId);
}

Envelope envelope = EnvelopeManager.GetInformation(authorizer, "<requesting_username>", "<envelope_id>");
foreach(ListCustomField field in envelope.listCustomFields) {
    Console.Write("Field Name: " + field.Name);
    Console.Write("Field Value: " + field.Value);
}

Where to find Docusign API credential information for your company

  1. Log into your docusign.net account
  2. Navigate to the dropdown menu on your profile picture (top right corner)
  3. Click Preferences
  4. Navigate to API under Account Administration (you can also generate your own demo integrator key here)

What is the username for in the REST action calls?

Your docusign account can have many users associated with it. Depending on who's preforming the action, the rest api base url, and api version may be different. So supplying the username (for a web app where the user is the logged in user, or the user that the applicaiton is preforming an operation on) finds the correct information to supply the authorizer with prior to building a REST transaction.

Do I have to build a strongly typed class for every REST response?

No. You can utilize either the ExecuteRequestToJObject(), or ExecuteRequestToString() method that the authorizer provides.

Do I have to provide the REST API credentials everytime I made a REST call?

No. Add your credentials to your applicaitons config file (or db), create the authorizer once, cache it and pass it to each REST call.

Demo Credentials

You can either use my demo credentials or your own. If you use your own, make sure to update the Unit Test classes with your information.

Docusign Demo Credentials (this will expire): uri: demo.docusign.net user: r@cky.bz pass: CloudSpokes

I want to add more actions to the library

Docusign REST API Guide: http://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm Docusign REST API Explorer: http://iodocs.docusign.com Docusign API Walkthroughs: http://iodocs.docusign.com/APIWalkthroughs

  1. Create a new <rest_type>Manager.cs class
  2. Create a method for each REST API call you need
  3. Determine if you need a strongly typed class, or if you can use a simple JObject, or parse a string.
  4. Create a Unit Test
  5. Be Happy