Skip to content

Instantly share code, notes, and snippets.

@codingdawg
Created June 29, 2017 16:34
Show Gist options
  • Save codingdawg/67bcd002d8fb1b8f2fd7b9c2977e1ec9 to your computer and use it in GitHub Desktop.
Save codingdawg/67bcd002d8fb1b8f2fd7b9c2977e1ec9 to your computer and use it in GitHub Desktop.
Imports System
Imports System.Collections.Generic
Imports System.Xml
Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Model
Imports Newtonsoft.Json
Imports System.IO
Imports System.Text
Namespace PlayGround
Public Module Module1
Sub Main(args As String())
Try
Dim docusignApiTest = New DocuSignApiTest()
docusignApiTest.GetDocumentRecipe()
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
Console.ReadLine()
End Sub
End Module
Public Class DocuSignApiTest
Public Sub GetDocumentRecipe()
Dim envelopeId As String = ""
Dim accountId As String = Init()
Dim envApi = New EnvelopesApi()
Dim docStream = envApi.GetDocument(accountId, envelopeId, "1")
' let's save the document to local file system
Dim filePath As String = "C:\temp\" + Path.GetRandomFileName() + ".pdf"
Using stream = File.Create(filePath)
docStream.CopyTo(stream)
End Using
End Sub
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 = "{""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
End Class
End Namespace
@amberino
Copy link

I'm just curious if the code above is for a console application only? I'm trying to utilize the docusign api from my vb.net web application and am having difficulties implementing it. At this point, I'm just trying to get logged in/authenticated. Your example looks like it could work for me.

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