Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save troywdocusign/8210ea585bb907d71badb6686d8db307 to your computer and use it in GitHub Desktop.
Save troywdocusign/8210ea585bb907d71badb6686d8db307 to your computer and use it in GitHub Desktop.
12107857 - DocuSign Create Enveloper
using System.Collections.Generic;
using System.IO;
using System;
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
namespace CSharp_example
{
class Program
{
private const string accessToken = "XXXX";
private const string accountId = "XXXX";
private const string AccountId = accountId;
private const string documentBase64 = "XXXX";
private static string signerEmail = "test@test.com";
private static string signerName = "Test Signer";
static async Task<string> SendEnvelope()
{
var docuSignClient = new DocuSignClient("https://demo.docusign.net/restapi");
docuSignClient.Configuration.DefaultHeader.Add("Authorization", $"Bearer {accessToken}");
var envelopesApi = new EnvelopesApi(docuSignClient);
// Prepare the envelope definition
var envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = "Please sign this document",
Documents = new List<Document>
{
new Document
{
DocumentBase64 = documentBase64,
Name = "TestDocument.pdf",
FileExtension = "pdf",
DocumentId = "1"
}
},
Recipients = new Recipients
{
Signers = new List<Signer>
{
new Signer
{
Email = signerEmail,
Name = signerName,
RecipientId = "1",
Tabs = new Tabs
{
SignHereTabs = new List<SignHere>
{
new SignHere
{
DocumentId = "1",
PageNumber = "1",
RecipientId = "1",
TabLabel = "SignHereTab",
XPosition = "100",
YPosition = "100"
}
}
}
}
}
},
Status = "sent"
};
try
{
// Call the create envelope endpoint using the SDK method
var results = await envelopesApi.CreateEnvelopeAsync(AccountId, envelopeDefinition);
return results.EnvelopeId;
}
catch (ApiException ex)
{
var errorCode = ex.ErrorCode; // returns 500
var errorMessage = ex.ErrorMessage; // returns ""
}
return "";
}
// The mainline
static void Main()
{
MainAsync().GetAwaiter().GetResult();
}
static async Task MainAsync()
{
Console.WriteLine("Starting...");
string envelopeId = await SendEnvelope();
Console.WriteLine("Done - EnevelopeId: " + envelopeId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment