Last active
March 24, 2017 18:26
-
-
Save codingdawg/3791af681a59b9f3084b14b47b970893 to your computer and use it in GitHub Desktop.
Posts an envelope with a number tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DocuSign.eSign.Api; | |
using DocuSign.eSign.Client; | |
using DocuSign.eSign.Model; | |
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
namespace PlayGround | |
{ | |
public class DocusignApiPlayground | |
{ | |
public string Init() | |
{ | |
string username = ""; | |
string password = ""; | |
string integratorKey = ""; | |
// initialize client for desired environment (for production change to www) | |
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi"); | |
Configuration.Default.ApiClient = apiClient; | |
// configure 'X-DocuSign-Authentication' header | |
string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}"; | |
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); | |
// we will retrieve this from the login API call | |
string accountId = null; | |
///////////////////////////////////////////////////////////////// | |
// STEP 1: LOGIN API | |
///////////////////////////////////////////////////////////////// | |
// login call is available in the authentication api | |
AuthenticationApi authApi = new AuthenticationApi(); | |
LoginInformation loginInfo = authApi.Login(); | |
// parse the first account ID that is returned (user might belong to multiple accounts) | |
accountId = loginInfo.LoginAccounts[0].AccountId; | |
// Update ApiClient with the new base url from login call | |
apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl); | |
return accountId; | |
} | |
public void CreateEnvelopeWithNumberTab() | |
{ | |
string accountId = Init(); | |
//=========================================================== | |
// Step 2: Create A Draft Envelope | |
//=========================================================== | |
// Read a file from disk to use as a document. | |
byte[] fileBytes = File.ReadAllBytes(@""); | |
EnvelopeDefinition envDef = new EnvelopeDefinition(); | |
envDef.EmailSubject = "[DocuSign C# SDK] - Envelope with Number tab"; | |
// Add a document to the envelope | |
Document doc = new Document(); | |
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); | |
doc.Name = "TestFile.pdf"; | |
doc.DocumentId = "1"; | |
envDef.Documents = new List<Document>(); | |
envDef.Documents.Add(doc); | |
// Add a recipient to sign the documeent | |
Signer signer = new Signer(); | |
signer.Email = "Janedoe@acme.com"; | |
signer.Name = "Jane Doe"; | |
signer.RecipientId = "1"; | |
// Create a |Number| tab somewhere on the document for the recipient to enter a value | |
signer.Tabs = new Tabs() | |
{ | |
NumberTabs = new List<Number>() | |
}; | |
var numberTab = new Number() | |
{ | |
DocumentId = "1", | |
PageNumber = "1", | |
RecipientId = "1", | |
XPosition = "100", | |
YPosition = "100", | |
Width = 80 | |
}; | |
signer.Tabs.NumberTabs.Add(numberTab); | |
envDef.Recipients = new Recipients(); | |
envDef.Recipients.Signers = new List<Signer>(); | |
envDef.Recipients.Signers.Add(signer); | |
envDef.Status = "sent"; | |
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) | |
EnvelopesApi envelopesApi = new EnvelopesApi(); | |
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); | |
Console.WriteLine(envelopeSummary); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment