0

I am creating demo application which Docusing pass file and signer dynamically, for that i need to use docusign templateid and pass details, i can pass file using templateid which signer already defined in template itself, now i want to pass multiple signer as dynamically.For that need to use templateRoles.

 Dim json As New Chilkat.JsonObject
    json.UpdateString("documents[0].name", "Testing.pdf")
    json.UpdateString("documents[0].documentBase64", base64String)
    json.UpdateString("documents[0].documentId", "2")
    json.UpdateString("emailSubject", "DocuSign REST API Testing Sample")
    json.UpdateString("emailBlurb", "Create and send an envelope from a document.")
    json.UpdateString("templateId", "xxxxx-xxxxx-xxxxx-xxxx-xxxx")
    json.UpdateString("templateRoles", "{roleName: Signer 1, name: Aravind, email: aravind@gmail.com, recipientId: 1}") ' Here i pass template role for signer 1, and also need to pass multiple signer.
    json.UpdateString("status", "sent")

    rest.AddHeader("X-DocuSign-Authentication", "{ ""Username"":    ""DocuSign@example.com"",  ""Password"":""DocuSign_password"",  ""IntegratorKey"":""DocuSign_Integrator_Key"" }")
     

    rest.AddHeader("Content-Type", "application/json")
    rest.AddHeader("Accept", "application/json")

    Dim sbRequestBody As New Chilkat.StringBuilder
    json.EmitSb(sbRequestBody)


    Dim sbResponseBody As New Chilkat.StringBuilder

    success = rest.FullRequestSb("POST", "/restapi/v2.1/accounts/xxxxxx/envelopes", sbRequestBody, sbResponseBody)
    Dim respStatusCode As Integer = rest.ResponseStatusCode

Here i paste code for ur reference, in that email,password,key everything i chanage,bcz it releted to security purpose. When i pass templateroles with values i get error.For above code i get following error return from api.

"errorCode":"INVALID_REQUEST_PARAMETER","message":"The request contained at least one invalid parameter. 'recipientId' not set for recipient."

Pls help me to solve this error.

Regards, Aravind

Larry K
  • 47,808
  • 15
  • 87
  • 140
Aravind Aravind
  • 179
  • 1
  • 10

2 Answers2

2

Here is code using the SDK:

Imports System
Imports System.Collections.Generic
Imports DocuSign.eSign.Api
Imports DocuSign.eSign.Client
Imports DocuSign.eSign.Model
Imports Microsoft.AspNetCore.Mvc


    Private Function DoWork(ByVal signerEmail As String, ByVal signerName As String, ByVal ccEmail As String, ByVal ccName As String, ByVal accessToken As String, ByVal basePath As String, ByVal accountId As String, ByVal templateId As String) As String
        Dim config = New Configuration(New ApiClient(basePath))
        config.AddDefaultHeader("Authorization", "Bearer " & accessToken)
        Dim envelopesApi As EnvelopesApi = New EnvelopesApi(config)
        Dim envelope As EnvelopeDefinition = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, templateId)
        Dim result As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, envelope)
        Return result.EnvelopeId
    End Function

Private Function MakeEnvelope(ByVal signerEmail As String, ByVal signerName As String) As EnvelopeDefinition
    Dim buffer As Byte() = System.IO.File.ReadAllBytes(Config.docPdf)
    Dim envelopeDefinition As EnvelopeDefinition = New EnvelopeDefinition()
    envelopeDefinition.EmailSubject = "Please sign this document"
    Dim doc1 As Document = New Document()
    Dim doc1b64 As String = Convert.ToBase64String(buffer)
    doc1.DocumentBase64 = doc1b64
    doc1.Name = "Lorem Ipsum"
    doc1.FileExtension = "pdf"
    doc1.DocumentId = "3"
    envelopeDefinition.Documents = New List(Of Document) From {
        doc1
    }
    Dim signer1 As Signer = New Signer With {
        .Email = signerEmail,
        .Name = signerName,
        .ClientUserId = signerClientId,
        .RecipientId = "1"
    }
    Dim signHere1 As SignHere = New SignHere With {
        .AnchorString = "/sn1/",
        .AnchorUnits = "pixels",
        .AnchorXOffset = "10",
        .AnchorYOffset = "20"
    }
    Dim signer1Tabs As Tabs = New Tabs With {
        .SignHereTabs = New List(Of SignHere) From {
            signHere1
        }
    }
    signer1.Tabs = signer1Tabs
    Dim recipients As Recipients = New Recipients With {
        .Signers = New List(Of Signer) From {
            signer1
        }
    }
    envelopeDefinition.Recipients = recipients
    envelopeDefinition.Status = "sent"
    Return envelopeDefinition
End Function
Inbar Gazit
  • 12,566
  • 1
  • 16
  • 23
  • Could u provide list of references need to add and namespace as well as.Docusign dll 4.3 i installed using nuget, any other need to install ? And also i getting error in MakeEnvelope - screenshot http://prntscr.com/ulknyp , is it need to generate method - Right click and generate – Aravind Aravind Sep 22 '20 at 06:20
  • Updated the answer above for this. – Inbar Gazit Sep 22 '20 at 16:21
  • Very Very Thanks , its working fine Thanks again... i can send multiple file with multiple signer also.Thanks a lot. – Aravind Aravind Sep 23 '20 at 10:30
1

Try to remove recipientId: 1 from the JSON in line 8.

But I strongly suggest you reconsider your architecture choices. You are using legacy authentication which is not very secure.

You could use the C# SDK, which is a Nuget package and works just as well with VB.NET and that would help you make these calls without using JSON and also using modern OAuth that is much more secure.

Inbar Gazit
  • 12,566
  • 1
  • 16
  • 23
  • Hi, Thanks for ur reply, after i remove recipient:1 from templateroles, i get different error. {{"errorCode":"INVALID_REQUEST_BODY","message":"The request body is missing or improperly formatted. Could not cast or convert from System.String to System.Collections.Generic.List`1[API_REST.Models.v2_1.templateRole]."}} -------- And that line like this json.UpdateString("templateRoles", "{[roleName:Signer1,name:Aravind,email:aravind@gmail.com]}") – Aravind Aravind Sep 18 '20 at 03:59
  • And could u provide piece of code in vb.net which same as above code using docusign sdk inclusing what name space and reference need to add as well as ? i already installed docusign dll 4.3 – Aravind Aravind Sep 18 '20 at 06:05
  • json.UpdateString("templateRoles", "{roleName: Signer 1, name: Aravind, email: aravind@gmail.com, recipientId: 1}") ' Here i pass template role for signer 1, and also need to pass multiple signer. In this line, each element should be in double quotes to make this valid JSON. Please correct and try again. – Inbar Gazit Sep 18 '20 at 15:50
  • Hi, i am changed in this way still getting same error -- formatted error json.UpdateString("templateRoles", "{""roleName:Signer1"", ""Name:Aravind"", ""Email:aravind@gmail.com""}") – Aravind Aravind Sep 19 '20 at 06:42
  • Hi, i tried 2 different ways , still getting format error json.UpdateString("templateRoles", "{""roleName"": ""Signer1"",""Name"": ""Aravind"",""Email"": ""aravind@gmail.com""}")--- json.UpdateString("templateRoles", "{""roleName:Signer1"", ""Name:Aravind"", ""Email:aravind@gmail.com""}") – Aravind Aravind Sep 19 '20 at 06:55
  • { \"templateId\": \"${template_id}\", \"templateRoles\": [ { \"email\": \"${SIGNER_EMAIL}\", \"name\": \"${SIGNER_NAME}\", \"roleName\": \"signer\" }, { \"email\": \"${CC_EMAIL}\", \"name\": \"${CC_NAME}\", \"roleName\": \"cc\" } ], \"status\": \"sent\" }" – Inbar Gazit Sep 20 '20 at 21:52
  • https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote has this code in various languages. – Inbar Gazit Sep 20 '20 at 21:52
  • your issue is that you are not formatting JSON correctly. Each element has to be enclosed in double quotes ("") – Inbar Gazit Sep 20 '20 at 21:53
  • Could u provide in vb.net and my code is ------ json.UpdateString("templateRoles", "{roleName: Signer 1, name: Aravind, email: aravind@gmail.com}") , pls see full code in description, form above code without templateroles it works fine, mean i can send template with predefined singer in docusign login. – Aravind Aravind Sep 21 '20 at 03:36
  • hi here i attach json value in Test Visualzer in break point from Visual Studio ---http://prntscr.com/ukulwy pls check is it correct format, i can pass without square bracket,still invalid format error – Aravind Aravind Sep 21 '20 at 04:27
  • I think you should change gears and use the SDK as this is too hard. I'll add an answer with SDK code, you'll need to add the nuget and all the dlls needed and namespaces. – Inbar Gazit Sep 21 '20 at 15:40
  • Could u provide list of references need to add and namespace as well as.Docusign dll 4.3 i installed using nuget, any other need to install ? – Aravind Aravind Sep 22 '20 at 06:24