Skip to content

Instantly share code, notes, and snippets.

@codingdawg
Created March 22, 2017 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingdawg/1ecbed65aaf705871d5a63e8ccb6ec7f to your computer and use it in GitHub Desktop.
Save codingdawg/1ecbed65aaf705871d5a63e8ccb6ec7f to your computer and use it in GitHub Desktop.
Creates an envelope with conditional fields based on Radio Group & text tab
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using DocuSign.eSign.Api;
using System.IO;
using Newtonsoft.Json;
namespace PlayGround
{
public class DocusignApiPlayground
{
private string Init()
{
string username = "xxxx";
string password = "xxxx";
string integratorKey = "xxxxxxxxxxxxxxxx";
// 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 CreateEnvelopeConditionalFields()
{
string accountId = Init();
//===========================================================
// Step 2: Create A Draft Envelope
//===========================================================
// Read a file from disk to use as a document.
byte[] fileBytes = File.ReadAllBytes(@""); //Specify file path here
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Conditional Fields";
// 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 = "xxxxx@xxxxxxx.com";
signer.Name = "Jane Doe";
signer.RecipientId = "1";
signer.Tabs = new Tabs()
{
TextTabs = new List<Text>(),
RadioGroupTabs = new List<RadioGroup>()
};
var textTab = new Text()
{
DocumentId = "1",
PageNumber = "1",
RecipientId = "1",
XPosition = "100",
YPosition = "100",
Height = "11",
Width = "42",
ConditionalParentLabel = "RadioGroupTest",
ConditionalParentValue = "Y"
};
var radioGroup = new RadioGroup()
{
GroupName = "RadioGroupTest",
DocumentId = "1",
RecipientId = "1",
Radios = new List<Radio>()
{
new Radio()
{
PageNumber = "1",
XPosition = "100",
YPosition = "70",
Value = "Y"
},
new Radio()
{
PageNumber = "1",
XPosition = "130",
YPosition = "70",
Value = "N"
}
}
};
signer.Tabs.TextTabs.Add(textTab);
signer.Tabs.RadioGroupTabs.Add(radioGroup);
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