The complete, working code is below, but I need to add a preface about where to get the info. <deep breath> Here goes
Don't confuse any Docusign account you may currently have with the Docusign Sandbox login.
So, now you have a dev user name, pass, and app key. In the top right corner click the user icon (your initials) and get your acccount ID. Again, note that this is not the paid account that you may or not have, this is the sandbox account id.
The 'LoginInfo' method is something of a 'hello world', it will bring back some basic account info
The 'SendEnvelope' method will send an email to the email address hard coded into the JSON above. That person can sign, and the signed document will be emailed back to you.
Imports System.IO
Imports System.Net
Public Class Test6
Public Sub LogonInfo(strUserName As String, strPassword As String, strIngegratorKey As String)
Try
'needed to upgrade my project to .NET 4.5.1 to have this available
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
'form the url
Dim oRequest As System.Net.HttpWebRequest
Dim oResponse As System.Net.WebResponse = Nothing
Dim oPostStream As System.IO.Stream = Nothing
' Create the web request
oRequest = DirectCast(System.Net.WebRequest.Create(strUrl), System.Net.HttpWebRequest)
oRequest.Method = "GET"
oRequest.Accept = "application/json"
oRequest.ContentType = "application/json"
' Add authentication to request
oRequest.Headers.Add("X-DocuSign-Authentication",
String.Format("<DocuSignCredentials><Username>{0}</Username><Password>{1}</Password><IntegratorKey>{2}</IntegratorKey></DocuSignCredentials>", strUserName, strPassword, strIngegratorKey))
'oRequest.ContentLength = 0
' Get the response
oResponse = DirectCast(oRequest.GetResponse(), System.Net.WebResponse)
'convert the response to a Stream
Dim oStream As System.IO.Stream = oResponse.GetResponseStream()
'convert the Stream to a StreamReader
Dim oStreamReader As New System.IO.StreamReader(oStream)
'read the response into a String
Dim strResponse As String = oStreamReader.ReadToEnd
Stop
'This is the result of this call
'NOTE: the 'accountID' is neede for the envelope call
'{
' "loginAccounts": [{
' "name": "my account name",
' "accountId": "12345678",
' "isDefault": "true",
' "userName": "Steve Gray",
' "userId": "00000000-0000-0000-0000-000000000000",
' "email": "me@myemail.com",
' "siteDescription": ""
' }]
'}
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub SendEnvelope(strAccountID As String, strUserName As String, strPassword As String, strIngegratorKey As String)
Try
ServicePointManager.Expect100Continue = True
'needed to upgrade my project to .NET 4.5.1 to have this available
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim strJSON As String
Dim strFile As String = "c:\temp\sample.pdf"
'Convert the PDF to a stream, then save the stream into a string
Dim doc3PdfBytes As String = Convert.ToBase64String(System.IO.File.ReadAllBytes(strFile))
'This is the JSON document that holds all the information for the signing
Dim oEnvelope As New StreamReader("Envelope.json")
'open it, read it into a string
strJSON = oEnvelope.ReadToEnd
'do a string replace, call the pdf into the json. This will be big
strJSON = Replace(strJSON, "[PDF]", doc3PdfBytes)
'form the url
Dim oRequest As System.Net.HttpWebRequest
Dim oResponse As System.Net.WebResponse = Nothing
Dim oPostStream As System.IO.Stream = Nothing
'call the JSON string into a byte array
Dim byteData() As Byte
byteData = System.Text.UTF8Encoding.UTF8.GetBytes(strJSON)
' Create the web request
oRequest = DirectCast(System.Net.WebRequest.Create(strUrl), System.Net.HttpWebRequest)
oRequest.Method = "POST"
oRequest.Accept = "application/json"
oRequest.ContentType = "application/json"
oRequest.ContentLength = strJSON.Length
' Add authentication to request
'THIS is the hard part to figure out
oRequest.Headers.Add("X-DocuSign-Authentication",
String.Format("<DocuSignCredentials><Username>{0}</Username><Password>{1}</Password><IntegratorKey>{2}</IntegratorKey></DocuSignCredentials>", strUserName, strPassword, strIngegratorKey))
'send our document
oPostStream = oRequest.GetRequestStream()
oPostStream.Write(byteData, 0, byteData.Length)
' Get the response
oResponse = DirectCast(oRequest.GetResponse(), System.Net.WebResponse)
'convert the response to a Stream
Dim oStream As System.IO.Stream = oResponse.GetResponseStream()
'convert the Stream to a StreamReader
Dim oStreamReader As New System.IO.StreamReader(oStream)
'read the response into a String
Dim strResponse As String = oStreamReader.ReadToEnd
Stop
'This is the result of this call.
'{
' "envelopeId": "00000000-0000-0000-0000-000000000000",
' "uri": "/envelopes/00000000-0000-0000-0000-000000000000",
' "statusDateTime": "2020-10-12T14:53:40.2030000Z",
' "status": "sent"
'}
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class