Elijah Murray
Elijah Murray

Reputation: 2172

Docusign Not Generating Multiple Embedded Recipient Views

I am using the Docusign Rest API, through a gem for Rails. I have 2 recipients, and need both of them to sign the document.

It should work like this:

Instead it breaks when I reloads the iframe for the 2nd signer. It generates the envelope, with my second signer with its unique ID, email etc. However when I then create the recipient view, it returns nil.

How do I get signer 1 to sign, then load it for the second signer right after, with all the custom fields filled both times?

def deliver(signing_borrower)

    client = DocusignRest::Client.new
    hashData = {
      status: 'sent',
      template_id: my_id
      signers: [
        {
          embedded: true,
          name: signing_borrower.name,
          email: signing_borrower_email,
          role_name: if (signing_borrower==borrower) then 'Borrower' else 'Co-borrower' end
        }
      ]
    }
    generate_liabilities
    hashData[:signers][0][:tabs] = if (signing_borrower==borrower) then custom_fields else co_borrower_custom_fields end


    #if there is a coborrower, add that data to the form as the second signer
    if co_borrower
      if signing_borrower==co_borrower then opposite_of_signing_borrower = borrower else opposite_of_signing_borrower = co_borrower end

      borrower2= {
        name: opposite_of_signing_borrower.name,
        email: signing_borrower_email(opposite_of_signing_borrower),
        role_name: if (opposite_of_signing_borrower==co_borrower) then 'Co-borrower' else 'Borrower' end
      }

      #add second borrower to hash to generate envelope with all form fields filled
      hashData[:signers] << borrower2
      hashData[:signers][1][:tabs] = {
          textTabs: text_tabs,
          checkboxTabs: checkbox_tabs
        }
    end


    response = client.create_envelope_from_template hashData
    self.envelope_id = response["envelopeId"]
    self.signing_url = DocusignRest::Client.new.get_recipient_view({
      envelope_id: self.envelope_id,
      name: signing_borrower.name,
      email: signing_borrower_email(signing_borrower),
      return_url: return_url
    })

    response
  end

The hashData

{:status=>"sent",
 :email=>
  {:subject=>"Application...",
   :body=>"please sign...."},
 :template_id=>"XXXX-XXXX-XXXX",
 :signers=>
  [{:embedded=>true,
    :name=>"DAVID L. TESTCASE",
    :email=>"[email protected]",
    :role_name=>"Borrower",
    :tabs=>
     {:textTabs=>
       [{:tablabel=>"phone",
         :name=>"phone",
         :value=>"717-717-7171"}]
     }
   },
   {:name=>"MARISOL TESTCASE",
    :email=>"[email protected]",
    :role_name=>"Co-borrower",
    :tabs=>
      {:textTabs=>
         [{:tablabel=>"phone",
         :name=>"phone",
         :value=>"717-717-7171"}]
     }
  }]}

Upvotes: 0

Views: 820

Answers (2)

Kim Brandl
Kim Brandl

Reputation: 13500

You can accomplish what you're trying to do by making 3 API calls:

  1. Create Envelope request, specifying both recipients as 'embedded/captive' by setting clientUserId property for each recipient.

  2. POST Recipient View request to get the URL to launch the first signer's signing session.

  3. POST Recipient View request to get the URL to launch the second signer's signing session.

Here's example JSON for those three calls.

1 - Create Envelope Request

POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes

{
  "emailSubject": "Please sign this",
  "emailBlurb": "Please sign...thanks!",
  "templateId": "064A7973-B7C1-41F3-A2AD-923CE8889333",
  "status": "sent",
  "templateRoles": [
   {
      "roleName": "Borrower",
      "name": "John Doe",
      "email": "[email protected]",
      "recipientId": "1",
      "clientUserId": "123",
      "tabs":{
            "textTabs":[
               {
                  "tabLabel":"BorrowerPhone",
                  "value":"717-717-7171"
               },
            ],
         }
    },
    {
      "roleName": "Co-borrower",
      "name": "Jane Doe",
      "email": "[email protected]",
      "recipientId": "2",
      "clientUserId": "567",
      "tabs":{
            "textTabs":[
               {
                  "tabLabel":"Co-borrowerPhone",
                  "value":"717-717-7171"
               },
            ],
         }
    }
  ]
}

A successful response will contain the Id of the newly created Envelope.

2 - POST Recipient View (for the First Recipient)

Make this call when the first signer is ready to sign. In the request URL, {{envelopeId}} is the Envelope Id value that was returned in the response of the Create Envelope request, and information in the request body corresponds to info you submitted for the first recipient in the Create Envelope request.

POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient

{
     "authenticationMethod": "Email",
     "clientUserId": "123",
     "userName": "John Doe",
     "email": "[email protected]",
     "returnUrl": "http://www.google.com"
}

The response will contain the URL that can be used to launch the DocuSign Envelope for the first recipient.

3 - POST Recipient View (for the Second Recipient)

Make this call when it's time for the second signer to sign. In the request URL, {{envelopeId}} is the Envelope Id value that was returned in the response of the Create Envelope request, and information in the request corresponds to info you submitted for the second recipient in the Create Envelope request.

POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient

{
     "authenticationMethod": "Email",
     "clientUserId": "567",
     "userName": "Jane Doe",
     "email": "[email protected]",
     "returnUrl": "http://www.google.com"
}

The response will contain the URL that can be used to launch the DocuSign Envelope for the second recipient.

Upvotes: 2

Ergin
Ergin

Reputation: 9356

I think the problem is in the JSON request body that you're building. I'm curious where you added the embedded => true property from, that's not in the API docs or examples. As far as I know that is not a valid property, but I think the DocuSign API is forgiving in that it doesn't error out when non-recognized properties are sent, it ignores them instead.

In general, when you are creating Embedded (aka "Captive") recipients you need to configure at least 3 properties for these recipients:

1.  email
2.  name
3.  clientUserId

All of these are client configurable (i.e. you can set them to whatever you want), however whatever values you use when adding each recipient.. you need to reference the same exact values when requesting a signing URL for them.

For example, to add two embedded recipients you can send the following (partial) request body:

"signers": [
    {
        "name": "Sally Doe",
        "email": "[email protected]"
        "clientUserId": "1000"
    },
    {
        "name": "John Doe",
        "email": "[email protected]"
        "clientUserId": "1001"
    }
]

If you do not specify the routingOrder for your recipients then it will default to routing order = 1. And if you don't specify a recipientId, the system will generate a unique GUID for each and assign to them.


Once your envelope has been created and your recipients have been added to it, you can then request the signing URLs, but as mentioned you'll need to reference the same values for name, email, and clientUserId.

For more info you can check out the page on Embedding functionality at the DocuSign Developer Center:

http://www.docusign.com/developer-center/explore/features

Upvotes: 0

Related Questions