Skip to content

Instantly share code, notes, and snippets.

@codingdawg
Created May 5, 2017 18:27
Show Gist options
  • Save codingdawg/a417908601c03f0dab267d9ce9104747 to your computer and use it in GitHub Desktop.
Save codingdawg/a417908601c03f0dab267d9ce9104747 to your computer and use it in GitHub Desktop.
Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Model
Imports Newtonsoft.Json
Imports System.Collections.Generic
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Http
Imports System.Net
Namespace PlayGround
Public Class DocusignApiPlayground
Public Function Init() As String
Dim username As String = ""
Dim password As String = ""
Dim integratorKey As String = ""
' initialize client for desired environment (for production change to www)
Dim apiClient As New ApiClient("https://demo.docusign.net/restapi")
Configuration.[Default].ApiClient = apiClient
' configure 'X-DocuSign-Authentication' header
Dim authHeader As String = (Convert.ToString((Convert.ToString((Convert.ToString("{""Username"":""") & username) + """, ""Password"":""") & password) + """, ""IntegratorKey"":""") & integratorKey) + """}"
Configuration.[Default].AddDefaultHeader("X-DocuSign-Authentication", authHeader)
' we will retrieve this from the login API call
Dim accountId As String = Nothing
'''//////////////////////////////////////////////////////////////
' STEP 1: LOGIN API
'''//////////////////////////////////////////////////////////////
' login call is available in the authentication api
Dim authApi As New AuthenticationApi()
Dim loginInfo As LoginInformation = 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
End Function
Public Sub CreateEnvelopeWithCustomFields()
Dim accountId As String = Init()
Dim fileBytes As Byte() = File.ReadAllBytes("Test.pdf")
Dim envDef = New EnvelopeDefinition()
envDef.EmailSubject = "[DocuSign C# SDK] - Custom Fields"
envDef.Status = "sent"
envDef.CustomFields = New CustomFields()
Dim textCustomField = New TextCustomField()
textCustomField.Name = "TransactionId"
textCustomField.Value = "KTI456"
Dim textCustomFields = New List(Of TextCustomField)()
textCustomFields.Add(textCustomField)
envDef.CustomFields.TextCustomFields = textCustomFields
' Add a recipient to sign the documeent
Dim signer As New Signer()
signer.Email = "Janedoe@acme.com"
signer.Name = "Jane Doe"
signer.RecipientId = "1"
signer.Tabs = New Tabs()
signer.Tabs.SignHereTabs = New List(Of SignHere)()
Dim signHereTab = New SignHere()
signHereTab.DocumentId = "1"
signHereTab.PageNumber = "1"
signHereTab.XPosition = "100"
signHereTab.YPosition = "100"
signer.Tabs.SignHereTabs.Add(signHereTab)
envDef.Recipients = New Recipients()
envDef.Recipients.Signers = New List(Of Signer)()
envDef.Recipients.Signers.Add(signer)
' Add a document to the envelope
Dim doc As New Document()
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes)
doc.Name = "TestFile.pdf"
doc.DocumentId = "1"
envDef.Documents = New List(Of Document)()
envDef.Documents.Add(doc)
Dim envelopesApi As New EnvelopesApi()
Dim envelopeSummary As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef)
Console.WriteLine(envelopeSummary)
End Sub
End Class
End Namespace
@JanKullawong
Copy link

Hi There,

I have aspx form like an invoice form. In my form have a feature to create a pdf file then it will proceed to the DocuSign. I try to use the DocuSign API by following your code. Can we set workflow by onclick then action CreateEnvelopeAPI.vb?
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Response.Redirect("CreateEnvelopeAPI.vb") End Sub
Anyway, Could you explain this code:
envDef.CustomFields = New CustomFields()

        Dim textCustomField = New TextCustomField()
        textCustomField.Name = "TransactionId"
        textCustomField.Value = "KTI456"

Many thanks!

@JanKullawong
Copy link

Hi,

How to called this page vai .aspx file?

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment