请求签名文档Rest API vb.net



我试图使用DocuSign . net客户端请求对我正在动态创建的文档签名。到目前为止,我已经能够将示例更改为vb.net,它可以工作(示例CS)。我正在转换"演练#4 -请求文档签名",大约在代码的一半处。现在我正在尝试使用信封。文档我在其他示例中见过,例如DocuSign示例。但似乎。document不是Envelope的一部分,即使这两个示例中的其余代码都转换为vb。

我的另一个选择是使用信封。AddDocument,但我似乎不能弄清楚它的期望。我应该传递fileBytes()作为字节,fileName作为字符串,索引作为整数。我已经尝试了几种不同的方法来获得fileBytes,但不断获得关于Invalid_Content_Type内容类型不支持的错误。

这是我一直在尝试的代码。关于如何将文件添加到信封的任何帮助将不胜感激。最终,我希望能够将多个文档添加到一个信封中。我可以让env.Create(docPath)工作,但这是没有帮助的。对于您能提供的任何帮助,我事先表示感谢。

Public Function RequestEsignature(email As String, rName As String, docPath As String, strSubject As String) As String
    main()
    Dim AccountEmail = My.Settings.docusignUserName
    Dim AccountPassword = My.Settings.docusignPassword
    Dim RecipientEmail = email
    Dim RecipientName = rName
    Dim documentPath = docPath
    Dim msgString As String
    Dim acct As Account = New Account()
    acct.Email = AccountEmail
    acct.Password = AccountPassword
    Dim result As Boolean = acct.Login()
    If Not result Then
        msgString = String.Format("There was an error logging in to DocuSign fo user {0}.nError Code:  {1}nMessage:  {2}", acct.Email, acct.RestError.errorCode, acct.RestError.message)
        MsgBox(msgString)
        Return Nothing
    End If
    Dim env As Envelope = New Envelope
    env.Login = acct
    env.Recipients = New Recipients()
    Dim signer(0) As Signer
    signer(0) = New Signer()
    signer(0).email = email
    signer(0).name = RecipientName
    signer(0).routingOrder = "1"
    signer(0).recipientId = "1"
    env.Recipients.signers = signer
    Dim envDocs = New Document()
    envDocs.documentId = "1"
    envDocs.name = "Test Document"
    envDocs.uri = docPath
    'Dim fileBytes As Byte()
    'Dim fileBytes = getByteArrayII(documentPath)
    'Dim oFile As FileInfo
    'oFile = New FileInfo(documentPath)
    'Dim oFileStream As FileStream = oFile.OpenRead()
    'Dim lBytes As Long = oFileStream.Length
    'If lBytes > 0 Then
    '    Dim fileData(lBytes - 1) As Byte
    '    oFileStream.Read(fileData, 0, lBytes)
    'If Not env.AddDocument(fileBytes, documentPath, 0) Then
    '    msgString = String.Format("The was an Error adding the Document." & vbCrLf & "Error Code:  {0} " & vbCrLf & "Message:  {1}", env.RestError.errorCode, env.RestError.message)
    '    MsgBox(msgString)
    '    Return Nothing
    'Else
    '    MsgBox("Doc Successfully Added")
    'End If
    'oFileStream.Close()
    'End If

    env.Status = "sent"
    env.EmailSubject = strSubject
    result = env.Create()
    If Not result Then
        If Not IsNothing(env.RestError) Then
            msgString = String.Format("Error Code:  {0}nMessage:  {1}", env.RestError.errorCode, env.RestError.message)
            MsgBox(msgString)
            Return Nothing
        Else
            MsgBox("There was a nondescript error while processing this request. nPLease verify all information is correct before trying again.")
            Return Nothing
        End If
    Else
        Return env.EnvelopeId
    End If
End Function
Private Function getByteArray(fileName As String) As Byte()
    Dim fInfo As New FileInfo(fileName)
    Dim numBytes As Long = fInfo.Length
    Dim fStream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
    Dim br As New BinaryReader(fStream)
    Dim data As Byte() = br.ReadBytes(CInt(numBytes))
    br.Close()
    fStream.Close()
    Return data
End Function
Private Function getByteArrayII(ByVal fileName As String) As Byte()
    Dim tempByte() As Byte = Nothing
    If String.IsNullOrEmpty(fileName) Then
        Throw New ArgumentNullException("FileName Not Provided")
        Return Nothing
    End If
    Try
        Dim fileInfo As New FileInfo(fileName)
        Dim numBytes As Long = fileInfo.Length
        Dim fStream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
        Dim binaryReader As New BinaryReader(fStream)
        tempByte = binaryReader.ReadBytes(Convert.ToInt32(numBytes))
        fileInfo = Nothing
        numBytes = 0
        fStream.Close()
        fStream.Dispose()
        Return tempByte
    Catch ex As Exception
        Return Nothing
    End Try
End Function

历史我是vb.net和编程的新手。到目前为止,我已经能够制作一个程序,允许用户输入客户端信息,并根据某些选择更改表单。我们有一个系统,它使用SQL数据在Word中进行邮件合并,然后通过DocuSign向客户发送PDF签名。我们使用SQL后端和vb.net前端。

最后,周末我一直在寻找答案,现在我正在寻求帮助。我已经在谷歌上搜索了所有我能想到的包括/排除的可能的术语。如果我公开要求,那就意味着我已经用尽了所有的资源。请不要发布任何DocuSign文档的链接,因为我已经访问了所有这些网站。谢谢你。

似乎没有Envelope类具有Document属性,而是Documents属性,似乎是一个数组。

你在这个链接上发布的c#示例似乎展示了如何附加文档:

// Attach the document(s) C#
envelope.Documents = new DocuSignWeb.Document[1];
DocuSignWeb.Document doc = new DocuSignWeb.Document();
doc.ID = "1";
doc.Name = "Document Name";
doc.PDFBytes = [Location of Document];
envelope.Documents[0] = doc;

在VB中应该是这样的:

'Attach the document(s) VB
envelope.Documents = new DocuSignWeb.Document(0);
Dim doc As New DocuSignWeb.Document()
doc.ID = "1"
doc.Name = "Document Name"
doc.PDFBytes = [Location of Document]
envelope.Documents(0) = doc

如果这不是您所面临的问题,请提供额外的详细信息。

显然,我学习vb, api和所有其他让我的程序工作所需的东西的方法是非常令人生畏的。我不确定这是我缺乏知识还是只是对代码的误解,但我终于能够弄清楚这一点。我的函数接受一个对象"client",它有Name和Email之类的东西,我还传递了一个文档路径列表和电子邮件的主题行。这将循环遍历文档列表并将它们添加到信封中。我也有一些添加标签的例子,这本身就是一个学习过程。我希望我是唯一一个不幸的人,不得不学习这么多不同的新概念,以至于这么简单的东西需要几个月的时间才能弄清楚,但如果不是这样,下面是代码:

    'Request Signature - Send Envelope
Public Function RequestEsignature(pClient As iqClient, docPaths As List(Of String), strSubject As String) As DocuSign.Integrations.Client.Envelope
    '*****************************************************************
    ' ENTER VALUES FOR FOLLOWING VARIABLES!
    '*****************************************************************
    Dim AccountEmail As String = My.Settings.docusignUserName
    Dim AccountPassword As String = My.Settings.docusignPassword
    Dim RecipientEmail As String = pClient.Email
    Dim RecipientName As String = pClient.Name.NameFL
    '*****************************************************************
    ' user credentials 
    Dim account As New Account()
    account = LoginToDocusign()
    If Not IsNothing(account) Then
    End If
    Dim result As Boolean ' = account.Login()
    ' create envelope object and assign login info
    Dim envelope As New Envelope()
    Dim recip = New Recipients()
    Dim signers = New List(Of Signer)
    Dim signer As New Signer()
    signer.email = RecipientEmail
    signer.name = RecipientName
    signer.routingOrder = "1"
    signer.recipientId = "1"
    Dim fileBytes = New List(Of Byte())
    Dim docNames = New List(Of String)
    Dim iqDoc As iqPublicClasses.iqDocement
    Dim docs = New List(Of Document)
    Dim doc As Document
    Dim tabs = New List(Of Tab)
    Dim tab As New Tab()
    Dim iTabs = New List(Of Tab)
    Dim iTab As New Tab()
    Dim dTabs = New List(Of DateSignedTab)
    Dim dTab As New DateSignedTab
    Dim rTabs = New List(Of RadioGroupTab)
    Dim rTab As New RadioGroupTab()
    Dim radios = New List(Of Radios)
    Dim radio As New Radios()
    tab = New Tab()
    tab.anchorIgnoreIfNotPresent = True
    tab.anchorString = "s1"
    tabs.Add(tab)
    dTab = New DateSignedTab
    dTab.anchorIgnoreIfNotPresent = True
    dTab.anchorString = "d1"
    dTabs.Add(dTab)
    iTab = New Tab()
    iTab.anchorIgnoreIfNotPresent = True
    iTab.anchorString = "i1"
    iTab.anchorYOffset = 15
    iTabs.Add(iTab)
    iTab = New Tab()
    iTab.anchorIgnoreIfNotPresent = True
    iTab.anchorString = "nri1"
    iTabs.Add(iTab)
    rTab = New RadioGroupTab()
    rTab.groupName = "RG1"
    rTab.anchorIgnoreIfNotPresent = True
    radio = New Radios()
    radio.anchorString = "rbn"
    radio.anchorIgnoreIfNotPresent = True
    radio.anchorYOffset = -10
    radios.Add(radio)
    radio = New Radios()
    radio.anchorString = "rby"
    radio.anchorIgnoreIfNotPresent = True
    radio.anchorYOffset = -10
    radios.Add(radio)
    rTab.radios = radios.ToArray
    rTabs.Add(rTab)
    signer.tabs = New Tabs()
    signer.tabs.signHereTabs = tabs.ToArray
    signer.tabs.dateSignedTabs = dTabs.ToArray
    signer.tabs.initialHereTabs = iTabs.ToArray
    signer.tabs.radioGroupTabs = rTabs.ToArray
    Dim cnt = 0
    For Each docName As String In docPaths
        cnt += 1
        iqDoc = New iqPublicClasses.iqDocement(docName)
        doc = New Document()
        doc.attachmentDescription = iqDoc.Name
        doc.name = String.Format("{0}{1}", iqDoc.Name, iqDoc.Extension)
        doc.fileExtension = iqDoc.Extension
        doc.uri = iqDoc.FullPath
        doc.documentId = cnt
        docs.Add(doc)
        docNames.Add(iqDoc.FullPath)
        fileBytes.Add(File.ReadAllBytes(iqDoc.FullPath))
    Next
    ' create envelope and send the signature request (since status is set to "sent")
    envelope.Login = account
    signers.Add(signer)
    recip.signers = signers.ToArray
    envelope.Recipients = recip
    envelope.Status = "sent"
    envelope.EmailSubject = strSubject
    result = envelope.Create(fileBytes, docs)
    If Not result Then
        If envelope.RestError IsNot Nothing Then
            Console.WriteLine("Error code:  {0}" & vbLf & "Message:  {1}", envelope.RestError.errorCode, envelope.RestError.message)
            Return Nothing
        Else
            Console.WriteLine("Error encountered while requesting signature from template, please review your envelope and recipient data.")
            Return Nothing
        End If
    Else
        Console.WriteLine("Signature request has been sent to {0}, envelopeId is {1}.", envelope.Recipients.signers(0).email, envelope.EnvelopeId)
        Return envelope
    End If
End Function

PS -正如我说过的,我对这个非常陌生,我正在学习。我知道这可能不是最优雅的方法或正确格式化的代码,但不幸的是,我几乎没有时间返回我编写的更新代码。希望有一天我能回去修复所有我在第一次创建它时不理解的东西。

最新更新