Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are two scopes of authorization:

  1. DigitalSignature.Sign

  2. DigitalSignature.Admin

User in first scope can perform all actions, except managing DocuSign users.

...

Code Block
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create({ClientId}).WithTenantId({TenantId}).WithClientSecret({ClientSecret}).Build();
var token = await app.AcquireTokenForClient(new string[] {“ClientId$"api://{ClientId"]}/.default"}).ExecuteAsync();

...

Or you can use DS ClientId and ClientSecret instead, which we can provide for you.

Then we need to add this token After getting the token, we add it to HttpClient header:

Code Block
HttpClient _client;
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

...

DS API has the following controllers:

  1. Documents: managing and processing documents (certificates and envelops) in DocuSign.

    - We can download PDF documents and envelops from DocuSign.
    Each document should be wrapped to envelope. Envelope can contain one or several documents.
    You need provide EnvelopeId and DocumentId for getting document:

    Code Block
    /api/v2/Documents/Document/{EnvelopeID}/{DocumentID}

    Or you can download envelop with documents inside:

    Code Block
    /api/v2/Documents/Envelop{EnvelopeID}

    Example:

    Code Block
    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetAuthHeader());
    _httpClient.DefaultRequestHeaders.Add("EnvelopeId", envelopeId.ToString());
     return _httpClient.GetStreamAsync(/api/v2/Documents/ + "Documents/Envelope?EnvelopeId=" + envelopeId.ToString());

    You can also download all signed envelops:

    Code Block
    /api/v2/Documents/Envelops


    - Convert Html document to PDF
    DocuSign sign only PDF documents. But you can send Html, Jpeg or MS Office document to DocuSign and DocuSign will convert it to pdf for you. Unfortunately, resulting PDF is not completely accessible.
    But if you want to have more control you can convert Html to PDF yourself. We use for this Telerik document processing library.
    You can use the following POST endpoint to convert Html to PDF:

    Code Block
    /api/

...

  1. v2/Documents/HTMLToPDF/

    Example:

    Code Block
    var json = JsonSerializer.Serialize(html);
    HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
    return await _httpClient.PostAsync(url, content);

    We can get portrait or landscape PDF, it depends on LandscapePageOrientation property of SignInfoHtml class. But default it’s false, so resulting PDF is in portrait mode.

  2. EVE: generating QR code for links to EVE
    /wiki/spaces/MAR/pages/2577891341 is a website designed for the purpose of allowing users to check the validity of digital documents issued by Transport Canada. 
    Using DS API, you can generate search result links to EVE or generate QR instead links.
    To get link:

    Code Block
    /api/v2/EVE/URL/

    Example:

    Code Block
    var resultData = await _httpClient.GetStringAsync(url);


    To get QR code:

    Code Block
    /api/v2/EVE/URL/QRCodeImageForURL/

    Example:

    Code Block
    var result = await _httpClient.GetStringAsync(url);

  3. Signing: signing documents (Html. PDF, JPG and MS Office docs) in DocuSign

    We can sign one or several documents by one request.
    You can specify signature position two ways:
    - absolution position (X, Y) or
    - anchor, marking some text as place where signature should be

    There are 3 ways to sign document:

    1. Embedded
      In this case you provide required information and get back url for signing ceremony.
      You need to provide the following information:
      - sender and signer names and emails
      - names of the documents
      - html content or base64 content (only in version 2) for each document
      - signature position (absolute or anchor) for each document
      Signing Html (POST):

      Code Block
      /api/v2/Signing/HTMLCeremonyUrl/

      Example:

      Code Block

...

    1.  var url = "/api/v2/Signing/HTMLCeremonyUrl/";
      var json = JsonSerializer.Serialize(info);
      HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");  
      return await _httpClient.PostAsync(url, content);

      Where info is the instance of the following class:

      Code Block
      public class SignInfoHtml : SignInfo
          {
              public SignInfoHtml() : base(){}
      
              public SignInfoHtml(IConfiguration iConfig) : base(iConfig) { }
      
              public int NumberOfDocuments
              {
                  get
                  {
                      return new int[] { HtmlContent.Length, DocumentName.Length }.Min();
                  }
              }
              public string[] HtmlContent { get; set; }
              public bool[] LandscapePageOrientation { get; set; };
              public bool HasAnchorString { get; set; }
              public string[] AnchorString { get; set; }
              public string[] AnchorUnits { get; set; }
              public int[] AnchorXOffset { get; set; }
              public int[] AnchorYOffset { get; set; }
          }

      Depending on LandscapePageOrientation property we can sign portrait or landscape document. By default it’s portrait, because LandscapePageOrientation is false by default.

      Signing non-Html (only in version 2) (POST):

      Code Block
      /api/v2/Signing/Templates/CeremonyUrl/

      Difference with HTML signing, that it used other info class:

      Code Block
      public class SignInfoBase64 : SignInfo
          {
              public SignInfoBase64() : base(){}
      
              public SignInfoBase64(IConfiguration iConfig) : base(iConfig) { }
      
              public int NumberOfDocuments
              {
                  get
                  {
                      return new int[] { Content.Length, DocumentName.Length }.Min();
                  }
              }
              public string[] Content { get; set; }     
          }


    2. Email Request
      In this case you provide the same information, but get not url, but email to signer email address with request to signer certificate.
      Signing Html (POST):

      Code Block
      /api/v2/Signing/Signing/HTMLEmailRequest/

      Example:

      Code Block
       var url = "/api/v2/Signing/Signing/HTMLEmailRequest/";
       var json = JsonSerializer.Serialize(info);
       HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
       return await _httpClient.PostAsync(url, content);

      Where info is information, required for singing (see above).

      Signing non-Html (only in version 2) (POST):

      Code Block
      /api/v2/Signing/Signing/EmailRequest/

    3. Template
      In this case we don’t send document to DocuSign, but use template, uploaded to DocuSign.
      We can get templates using the following endpoint (GET):

      Code Block
      /api/v2/Signing/Templates/

      Signing (POST):

      Code Block
      /api/v2/Signing/TemplateCeremonyUrl/

      Email request (POST):

      Code Block
      /api/v2/Signing/TemplateEmailRequest/

  1. Users: managing DocuSign users (require Admin scope)
    - Get list of all signers (GET)

    Code Block
    /api/v2/Signing/Users/Signers/


    - Create DocuSign user (POST)

    Code Block
    /api/v2/Signing/Users/Users/


    - Update user information (PUT)

    Code Block
    /api/v2/Signing/Users/Users


    - Delete user (DELETE)

    Code Block
    /api/v2/Signing/Users/Users/

Versioning

There are two version of DS API.

Current version is 2.

References

  1. DocuSign

  2. DS API (NCD Environment)

  3. DS API (NCA Environment)