Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codingdawg/46e72ae035a0c871ef558531f3efff58 to your computer and use it in GitHub Desktop.
Save codingdawg/46e72ae035a0c871ef558531f3efff58 to your computer and use it in GitHub Desktop.
Envelope with 3 cc recipients and 2 signers.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using Newtonsoft.Json;
namespace DocuSignApiTester
{
public class DocuSignApiBase
{
protected const string _username = "";
protected const string _integratorKey = "";
protected const string _password = "";
protected const string _baseUri = "https://demo.docusign.net/restapi";
protected string _authHeader;
public DocuSignApiBase()
{
// configure 'X-DocuSign-Authentication' header
_authHeader = "{\"Username\":\"" + _username + "\", \"Password\":\"" + _password + "\", \"IntegratorKey\":\"" + _integratorKey + "\"}";
}
public string Init()
{
// initialize client for desired environment (for production change to www)
ApiClient apiClient = new ApiClient(_baseUri);
Configuration.Default.ApiClient = apiClient;
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 class DocuSignProgram : DocuSignApiBase
{
public void CreateEnvelopeDuplicateRecipients()
{
string accountID = Init();
byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\temp\test.pdf");
var envDef = new EnvelopeDefinition()
{
EmailSubject = "Envelope with CC & Signers",
Status = "Sent",
Documents = new List<Document>()
{
new Document()
{
DocumentBase64 = System.Convert.ToBase64String(fileBytes),
Name = "Dummy",
DocumentId = "1"
}
},
Recipients = new Recipients()
{
CarbonCopies = new List<CarbonCopy>()
{
new CarbonCopy()
{
Email = "janecc@acme.com",
Name = "jane cc",
RecipientId = "1",
RoutingOrder = "1"
},
new CarbonCopy()
{
Email = "janecc@acme.com",
Name = "jane cc",
RecipientId = "3",
RoutingOrder = "3"
},
new CarbonCopy()
{
Email = "janecc@acme.com",
Name = "jane cc",
RecipientId = "5",
RoutingOrder = "5"
}
},
Signers = new List<Signer>()
{
new Signer()
{
Email = "janedoe@acme.com",
Name = "jane doe",
RecipientId = "2",
RoutingOrder = "2",
Tabs = new Tabs()
{
SignHereTabs = new List<SignHere>()
{
new SignHere()
{
DocumentId = "1", XPosition = "100", YPosition = "200", PageNumber = "1",
}
}
}
},
new Signer()
{
Email = "bobbydoe@acme.com",
Name = "bobbydoe Demo",
RecipientId = "4",
RoutingOrder = "4",
Tabs = new Tabs()
{
SignHereTabs = new List<SignHere>()
{
new SignHere()
{
DocumentId = "1", XPosition = "100", YPosition = "300", PageNumber = "1",
}
}
}
}
}
}
};
var 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