I am evaluating DocuSign for our demo product. I have created a demo using your RestApi libraries in ASP.Net MVC Project and is working fine.
I used the same code in our project but the code crashes with “Could not load assembly or reference” error. After a lot of R&D I found that the issue is because the library provided by DocuSign v3.0.0 is not signed.
As an alternate I started using v2.0.0 which is a signed library provided by DocuSign. The issue is resolved now but now I am getting an exception when trying to add Configuration header in Envelope “An item with the same key has already been added”. I have attached code sample for your reference.
public void Main()
{
AccountID = DocLogin();
EnvelopeID = CreateSendEnvelope(AccountID);
// if (!string.IsNullOrEmpty(EnvelopeID))
// EmbeddedSigning(AccountID, EnvelopeID);
}
private string DocLogin()
{
string accountId = null;
try
{
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
Configuration cfi = new Configuration(apiClient);
// configure 'X-DocuSign-Authentication' header
string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
cfi.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
// we will retrieve this from the login API call
AuthenticationApi authApi = new AuthenticationApi(cfi);
LoginInformation loginInfo = authApi.Login();
accountId = loginInfo.LoginAccounts[0].AccountId;
}
catch (Exception ex)
{
string inner = ex.Message;
}
return accountId;
}
private string CreateSendEnvelope(string accountID)
{
string pdfPath = Server.MapPath("~/Documents/Document.docx");
if (!string.IsNullOrEmpty(accountID))
{
if (System.IO.File.Exists(pdfPath))
{
byte[] fileBytes = System.IO.File.ReadAllBytes(pdfPath);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = "Document.docx";
doc.DocumentId = "1";
doc.FileExtension = "docx";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
Signer signer = new Signer();
signer.Email = userEmail;
signer.Name = userDisplayName;
signer.RecipientId = "1";
signer.ClientUserId = "1001";
signer.Tabs = new Tabs();
signer.Tabs.SignHereTabs = new List<SignHere>();
SignHere signHere = new SignHere();
signHere.DocumentId = "1";
signHere.PageNumber = "1";
signHere.RecipientId = "1";
signHere.XPosition = "90";
signHere.YPosition = "452";
signer.Tabs.SignHereTabs.Add(signHere);
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
envDef.Recipients.Signers.Add(signer);
// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
envelopesApi.Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);
return envelopeSummary.EnvelopeId;
}
}
return string.Empty;
}