Advertisement
Guest User

Example of C# DocuSign SDK

a guest
Apr 21st, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.97 KB | None | 0 0
  1. //The MIT License
  2.  
  3. //Copyright( c) 2016- DocuSign, Inc. (https://www.docusign.com)
  4.  
  5. //Permission is hereby granted, free of charge, to any person obtaining a copy
  6. //of this software and associated documentation files (the "Software"), to deal
  7. //in the Software without restriction, including without limitation the rights
  8. //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. //copies of the Software, and to permit persons to whom the Software is
  10. //furnished to do so, subject to the following conditions:
  11.  
  12. //The above copyright notice and this permission notice shall be included in all
  13. //copies or substantial portions of the Software.
  14.  
  15. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. //SOFTWARE.
  22. using DocuSign.eSign.Api;
  23. using DocuSign.eSign.Model;
  24. using DocuSign.eSign.Client;
  25.  
  26. namespace DocuSignSample
  27. {
  28.     class Program
  29.     {
  30.         static void Main(string[] args)
  31.         {
  32.             string username = "[EMAIL]";
  33.             string password = "[PASSWORD]";
  34.             string integratorKey = "[INTEGRATOR_KEY]";
  35.  
  36.             // initialize client for desired environment (for production change to www)
  37.             ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
  38.             Configuration.Default.ApiClient = apiClient;
  39.  
  40.             // configure 'X-DocuSign-Authentication' header
  41.             string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
  42.             Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
  43.  
  44.             // we will retrieve this from the login API call
  45.             string accountId = null;
  46.  
  47.             /////////////////////////////////////////////////////////////////
  48.             // STEP 1: LOGIN API        
  49.             /////////////////////////////////////////////////////////////////
  50.  
  51.             // login call is available in the authentication api
  52.             AuthenticationApi authApi = new AuthenticationApi();
  53.             LoginInformation loginInfo = authApi.Login();
  54.                
  55.             // parse the first account ID that is returned (user might belong to multiple accounts)
  56.             accountId = loginInfo.LoginAccounts[0].AccountId;
  57.                
  58.             // Update ApiClient with the new base url from login call
  59.             apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl);
  60.        
  61.             /////////////////////////////////////////////////////////////////
  62.             // STEP 2: CREATE ENVELOPE API        
  63.             /////////////////////////////////////////////////////////////////              
  64.                
  65.             // create a new envelope which we will use to send the signature request
  66.             EnvelopeDefinition envDef = new EnvelopeDefinition();
  67.             envDef.EmailSubject = "[DocuSign C# SDK] - Sample Signature Request";
  68.  
  69.             // provide a valid template ID from a template in your account
  70.             envDef.TemplateId = "[TEMPLATE_ID]";
  71.  
  72.             // assign recipient to template role by setting name, email, and role name.  Note that the
  73.             // template role name must match the placeholder role name saved in your account template.  
  74.             TemplateRole tRole = new TemplateRole();
  75.             tRole.Email = "[SIGNER_EMAIL]";
  76.             tRole.Name = "[SIGNER_NAME]";
  77.             tRole.RoleName = "[ROLE_NAME]";
  78.  
  79.             // add the roles list with the our single role to the envelope
  80.             List<TemplateRole> rolesList = new List<TemplateRole>() { tRole };
  81.             envDef.TemplateRoles = rolesList;
  82.  
  83.             // set envelope status to "sent" to immediately send the signature request
  84.             envDef.Status = "sent";
  85.  
  86.             // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
  87.             EnvelopesApi envelopesApi = new EnvelopesApi();
  88.             EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement