DocuSign Rest API send envelope using composite template - docusignapi

I have a composite template that I use to send the following:
1 document for signing
Another document that doesn't requiring signing, but is included
A document stored in a template
I am receiving the this error : Error performing web request. {
"errorCode": "UNSPECIFIED_ERROR",
"message": "Invalid length for a Base-64 char array or string." I have verified that the Base64 is a multiple of 4. I think that the issue is that I don't have the right content type. I am using Nintex and SharePoint to send the Rest API to DocuSign.
Content type: multipart/form-data;boundary=MY_BOUNDARY
Accept: application/json
Host: na2.docusign.net
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"emailSubject": "Contract Package for {ItemProperty:Title}",
"status" : "sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [
{
"email": "{WorkflowVariable:varCreatedByEmail}",
"name": "{WorkflowVariable:varCreatedByName}",
"recipientId": "1",
"roleName": "MI Employee",
"routingOrder": "1",
"tabs":
{"signerAttachmentTabs": [
{"anchorString": "/ea1/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Scope of Work Attachment",
"optional": "true",
"tabOrder": 1},
{"anchorString": "/ea2/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Pricing Attachment",
"optional": "true",
"tabOrder": 3}],
"textTabs":[
{"anchorString": "/ec1/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Scope of Work Text",
"disableAutoSize": true,
"width": 550,
"height": 220,
"tabOrder": 2},
{"anchorString": "/ec2/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Pricing Text",
"disableAutoSize": true,
"width": 550,
"height": 220,
"tabOrder": 4}]
}
},
{
"email": "{ItemProperty:E_x002d_Mail}",
"name": "{ItemProperty:Primary_x0020_Contact}",
"recipientId": "2",
"roleName": "Vendor",
"routingOrder": "2",
"tabs":
{"fullNameTabs": [
{"anchorString": "/vn/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"signHereTabs":[
{"anchorString": "/vs/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"dateSignedTabs":[
{"anchorString": "/dvs/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"initialHereTabs":[
{"anchorString": "/vi/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"titleTabs":[
{"anchorString": "/vt/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"emailAddressTabs":[
{"anchorString": "/ve/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"textTabs":[
{"anchorString": "/va1/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Address Line 1"},
{"anchorString": "/va2/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Address Line 2",
"required": false},
{"anchorString": "/va3/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Address Line 3",},
{"anchorString": "/vc/",
"anchorXOffset": "1",
"anchorYOffset": "0",
"tabLabel": "Vendor Name",
"disableAutoSize": true,
"width": 225,
"height": 32}]
}
},
{
"email": "{WorkflowVariable:varContractApproverEmail}",
"name": "{WorkflowVariable:varContractApproverName}",
"recipientId": "3",
"roleName": "MI Approver",
"routingOrder": "3",
"tabs":
{"signHereTabs":[
{"anchorString": "/as/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"dateSignedTabs":[
{"anchorString": "/das/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"fullNameTabs":[
{"anchorString": "/an/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"titleTabs":[
{"anchorString": "/at/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
,
"emailAddressTabs":[
{"anchorString": "/ae/",
"anchorXOffset": "1",
"anchorYOffset": "0"}]
}
} ]
}
} ],
"document": {
"documentId": 1,
"name": "{WorkflowVariable:varContractName}",
"documentbase64": "{WorkflowVariable:varContractBase64}"
}
},
{
"inlineTemplates": [
{
"sequence" : 3,
"recipients": {
"carbonCopies" : [
{
"email": "{WorkflowVariable:varCreatedByEmail}",
"name": "{Common:InitiatorsDisplayName}",
"recipientId": "1",
"roleName": "MI Employee",
"routingOrder": "1"
},
{
"email": "{ItemProperty:E_x002d_Mail}",
"name": "{ItemProperty:Primary_x0020_Contact}",
"recipientId": "2",
"roleName": "Vendor",
"routingOrder": "2"
},
{
"email": "{WorkflowVariable:varContractApproverEmail}",
"name": "{WorkflowVariable:varContractApproverName}",
"recipientId": "3",
"roleName": "MI Approver",
"routingOrder": "3"
}]
}
}],
"document": {
"documentId": 2,
"name": "{WorkflowVariable:varExhibitAName}",
"documentbase64": "{WorkflowVariable:varExhibitABase64}"
}
},
{
"serverTemplates": [
{
"sequence" : 6,
"templateId": "D7472F81-46F9-4BEB-9017-DFAD3C0BCE83"
}],
"inlineTemplates": [
{
"sequence" : 7,
"recipients": {
"signers" : [{
"email": "{WorkflowVariable:varCreatedByEmail}",
"name": "{Common:InitiatorsDisplayName}",
"recipientId": "1",
"roleName": "MI Employee",
"routingOrder": "1"
},
{
"email": "{ItemProperty:E_x002d_Mail}",
"name": "{ItemProperty:Primary_x0020_Contact}",
"recipientId": "2",
"roleName": "Vendor",
"routingOrder": "2",
"tabs": {
"textTabs": [
{
"tabLabel": "VendorName"}]}
},
{
"email": "{WorkflowVariable:varContractApproverEmail}",
"name": "{WorkflowVariable:varContractApproverName}",
"recipientId": "3",
"roleName": "MI Approver",
"routingOrder": "3"
}
]
}
}],
"document": {
"documentId": 4,
"name": "CCare_Pledge.pdf"
}
}]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varContractName}"; documentid="1"
<document bytes removed>
--MY_BOUNDARY--
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}"; documentid="2"
<document bytes removed>
--MY_BOUNDARY--
Content-Type: application/pdf
Content-Disposition: file; filename="CCare_Pledge.pdf"; documentid="4"
Link to base64-
http://www.mihomes.com/corp/vit/Base64.txt

In looking at the request you've posted, a few things jump out at me:
First, you've incorrectly specified the boundary separator for the part that specifies documentid=2 as "--MY_BOUNDARY--"
--MY_BOUNDARY--
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}"; documentid="2"
By including the -- at the end of this boundary string, you're indicating the end of the multipart message, so it's quite possible that DocuSign is not reading any of the request content that follows this string. I'd suggest changing this to "--MY_BOUNDARY"
Secondly, you're specifying document bytes multiple times for two of the documents (documentid=1 and documentid=2) -- once as part of the document object (using the documentbase64 attribute) in each Composite Template, and again in the additional parts of the multipart request. I'd suggest removing the documentbase64 attribute from the document object of each Composite Template object -- it's not needed if you're specifying the document bytes in additional parts of the multipart message.
Next, if CCare_Pledge.pdf is the first document contained in the Template you're using, then you should remove the document attribute (object) from that Composite Template object:
"document": {
"documentId": 4,
"name": "CCare_Pledge.pdf"
}
And also remove the final part of the request:
--MY_BOUNDARY--
Content-Type: application/pdf
Content-Disposition: file; filename="CCare_Pledge.pdf"; documentid="4"
This is not needed because the document's coming from the Template itself, so you don't need to specify document info in the request.
Finally, make sure that your request ends with the correct boundary terminator string:
--MY_BOUNDARY--
(The answer to this other post shows a good example of overall request structure with regard to boundary separators.)
Once you've implemented these suggested changes, your request structure should look like this:
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"emailSubject": "Contract Package for {ItemProperty:Title}",
"status" : "sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
...
}
}
],
"document": {
"documentId": 1,
"name": "{WorkflowVariable:varContractName}"
}
},
{
"inlineTemplates": [
{
"sequence" : 3,
"recipients": {
...
}
}
],
"document": {
"documentId": 2,
"name": "{WorkflowVariable:varExhibitAName}"
}
},
{
"serverTemplates": [
{
"sequence" : 6,
"templateId": "D7472F81-46F9-4BEB-9017-DFAD3C0BCE83"
}
],
"inlineTemplates": [
{
"sequence" : 7,
"recipients": {
...
}
}
]
}
]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varContractName}"; documentid="1"
<document bytes removed>
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}"; documentid="2"
<document bytes removed>
--MY_BOUNDARY--

Related

DocuSign: recipient signerAttachmentTabs inappropriately replicated

I'm trying to create an envelope using DocuSign REST API. The signature tabs are generated by converting the PDF signature fields, and a signerAttachment tab is added manually.
In the final envelope, there is (as expected) only one signHere tab, but three overlapping signerAttachment tabs, which must be acted upon (read: upload a file) before the envelope can be effectively signed.
Case details
The envelope has 2 documents, one of which has signature tabs generated by transforming PDF fields. There are two recipients, one signer and one "Carbon Copy". The signer, before completing the envelope, must upload an additional document, so I added a signerAttachmentTab.
The JSON sent to the API endpoint /restapi/v2.1/accounts/{accountId}/envelopes follows (null values omitted and sensitive information redacted):
{
"compositeTemplates": [
{
"compositeTemplateId": "0",
"document": {
"documentBase64": "(redacted)",
"documentId": "1",
"fileExtension": "pdf",
"name": "Summary",
"transformPdfFields": "true"
},
"inlineTemplates": [
{
"envelope": {
"emailBlurb": "Just a test for development. Ignore this message",
"emailSubject": "from unit-test 01"
},
"recipients": {
"carbonCopies": [
{
"email": "john.doe#company.com",
"name": "John Doe",
"recipientId": "00283187",
"roleName": "CCOPY",
"routingOrder": "1"
}
],
"signers": [
{
"email": "jane.dee#company.com",
"name": "Jane Dee",
"recipientId": "00283183",
"recipientSignatureProviders": [
{
"signatureProviderName": "(redacted)",
"signatureProviderOptions": {
"sms": "+000-000-000"
}
}
],
"roleName": "SIGNER",
"routingOrder": "1",
"tabs": {
"signerAttachmentTabs": [
{
"xposition": "10",
"yposition": "10",
"documentId": "3",
"name": "Attachment",
"pageNumber": "1",
"recipientId": "00283183",
"tabLabel": "Attach-document",
"tooltip": "SignerAttachment",
"xPosition": "10",
"yPosition": "10"
}
],
"signHereTabs": [
{
"anchorAllowWhiteSpaceInCharacters": "true",
"recipientId": "00283183",
"tabLabel": "firmatario_00283183\\*"
}
]
},
"userId": "00283183"
}
]
},
"sequence": "1"
}
]
},
{
"compositeTemplateId": "1",
"document": {
"documentBase64": "(redacted)",
"documentId": "2",
"fileExtension": "pdf",
"name": "sample0",
"transformPdfFields": "true"
},
"inlineTemplates": [
{
"customFields": {
},
"envelope": {
"emailBlurb": "Just a test for development. Ignore this message",
"emailSubject": "from unit-test 01"
},
"recipients": {
"carbonCopies": [
{
"email": "john.doe#company.com",
"name": "John Doe",
"recipientId": "00283187",
"roleName": "CCOPY",
"routingOrder": "1"
}
],
"signers": [
{
"email": "jane.dee#company.com",
"name": "Jane Dee",
"recipientId": "00283183",
"recipientSignatureProviders": [
{
"signatureProviderName": "(redacted)",
"signatureProviderOptions": {
"sms": "+000-000-000"
}
}
],
"roleName": "SIGNER",
"routingOrder": "1",
"tabs": {
"signerAttachmentTabs": [
{
"xposition": "10",
"yposition": "10",
"documentId": "3",
"name": "Attachment",
"pageNumber": "1",
"recipientId": "00283183",
"tabLabel": "Attach-document",
"tooltip": "SignerAttachment",
"xPosition": "10",
"yPosition": "10"
}
],
"signHereTabs": [
{
"anchorAllowWhiteSpaceInCharacters": "true",
"recipientId": "00283183",
"tabLabel": "firmatario_00283183\\*"
}
]
},
"userId": "00283183"
}
]
},
"sequence": "2"
}
]
},
{
"compositeTemplateId": "2",
"document": {
"documentBase64": "(redacted)",
"documentId": "3",
"fileExtension": "pdf",
"name": "sample1",
"transformPdfFields": "true"
},
"inlineTemplates": [
{
"envelope": {
"emailBlurb": "Just a test for development. Ignore this message",
"emailSubject": "from unit-test 01"
},
"recipients": {
"carbonCopies": [
{
"email": "john.doe#company.com",
"name": "John Doe",
"recipientId": "00283187",
"roleName": "CCOPY",
"routingOrder": "1"
}
],
"signers": [
{
"email": "jane.dee#company.com",
"name": "Jane Dee",
"recipientId": "00283183",
"recipientSignatureProviders": [
{
"signatureProviderName": "(redacted)",
"signatureProviderOptions": {
"sms": "+000-000-000"
}
}
],
"roleName": "SIGNER",
"routingOrder": "1",
"tabs": {
"signerAttachmentTabs": [
{
"xposition": "10",
"yposition": "10",
"documentId": "3",
"name": "Attachment",
"pageNumber": "1",
"recipientId": "00283183",
"tabLabel": "Attach-document",
"tooltip": "SignerAttachment",
"xPosition": "10",
"yPosition": "10"
}
],
"signHereTabs": [
{
"anchorAllowWhiteSpaceInCharacters": "true",
"recipientId": "00283183",
"tabLabel": "firmatario_00283183\\*"
}
]
},
"userId": "00283183"
}
]
},
"sequence": "3"
}
]
}
],
"notification": {
"expirations": {
"expireAfter": "2",
"expireEnabled": "true"
}
},
"status": "sent",
"transactionId": "55909b0d-b54f-454e-b966-e58ca5fb4e7e"
}
The envelope definition has been written following the guidelines by DocuSign, namely by inserting a composite template for each document and assigning the recipients to each one of them.
Now, I expect that, despite the same recipients being declared three times (one for each document), they will be merged in the final envelopes, as per this quote from the same page:
When you use multiple templates to create an envelope, two or more templates may define the same recipient (a recipient with the same role or even the same name as other recipients), creating duplicate recipients. You can automatically merge these duplicate recipients by making sure that each of these duplicate recipients has the same email, user name, and routing order. In this case, any duplicate recipients are merged together after all template overlays have been applied.
What I observe is that, in the final envelope, there is -- as expected -- only one signature field, but three overlapping signerAttachment field. Therefore, the signer has to upload the same file three times to complete the envelope.
A call to the endpoint /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/recipients/{recipientId}/tabs confirms the presence of three similar tabs:
{
"signHereTabs": [
{
"stampType": "signature",
"isSealSignTab": "false",
"name": "SignHere",
"tabLabel": "firmatario_00283183_Firma consulenza_001",
"scaleValue": "1",
"optional": "false",
"documentId": "3",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "391",
"yPosition": "719",
"width": "0",
"height": "0",
"tabId": "2cee0f3e-a2bb-4aae-a5b4-82c66b177c0a",
"tabType": "signhere"
}
],
"signerAttachmentTabs": [
{
"name": "Attachment",
"tabLabel": "Attach-document",
"scaleValue": "1",
"optional": "false",
"documentId": "3",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "10",
"yPosition": "10",
"width": "0",
"height": "0",
"tabId": "a67c3071-6ac4-4c3b-a20c-0197cda091ed",
"tabType": "signerattachment",
"tooltip": "SignerAttachment"
},
{
"name": "Attachment",
"tabLabel": "Attach-document",
"scaleValue": "1",
"optional": "false",
"documentId": "3",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "10",
"yPosition": "10",
"width": "0",
"height": "0",
"tabId": "c20809de-3792-4ff7-ab31-6f09a13f3fbc",
"tabType": "signerattachment",
"tooltip": "SignerAttachment"
},
{
"name": "Attachment",
"tabLabel": "Attach-document",
"scaleValue": "1",
"optional": "false",
"documentId": "3",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "10",
"yPosition": "10",
"width": "0",
"height": "0",
"tabId": "1d0c84cd-6511-47c2-a75f-73721ac2fb0f",
"tabType": "signerattachment",
"tooltip": "SignerAttachment"
}
]
}
Why the signerAttachment tabs are not merged like the signHere tabs and what can be done to merge them in the resulting envelope?
I believe the issue is that in the case of the SignHere tab, your InLineTemplate is not creating the SignHere tabs, it is providing/updating the settings for the existing tab where the tabLabel is "firmatario_00283183"
(The tab is existing because it was created as part of the PDF transformation.)
In contrast, your three definitions for the SignerAttachment tabs are each creating new tabs. So you're seeing the three new SignerAttachment tabs on the document.
Solution: only create as many SignerAttachment tabs as you want. There is no merging (supression) of tabs, just merging of the Recipients.
I will admit that I'm not a gonzo expert on CompositeTemplates. But I think I'm on reasonably firm ground here.
Each signerAttachmentTab specified in each compositeTemplate has specified the same document for placement - "documentId": "3", so each of your composites is placing a new signer attachment tab to the same document, ID 3. If you only want one signer attachment, only specify it in the requisite composite. For documentId = 3, that would be your third composite. If you want an attachment tab on each document, then make sure you specify the correct documentId.

JSON Docusign Inline mulitpule Documents

I have my Json working for single document and transforms the PDF fields, but when I try to add second document. I Get JSON Parse error.
This works
"document": {
"documentId": "1",
"name": "Test Contract With Fields.pdf",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
}
this also works but doesn't transforms the PDFFields.
"inlineTemplates": [
{
"documents": [
{
"documentBase64": "<Base64BytesHere>",
"documentId": "1",
"name": "test",
"transformPdfFields": "true"
},
{
"documentBase64": "<Base64BytesHere>",
"documentId": "2",
"name": "test 2",
"order": "2"
}
],
Adding Square [] and second document breaks. Tried making Documents
"document": [{
"documentId": "1",
"name": "Test Contract With Fields.pdf",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
},
{
"documentId": "2",
"name": "Test Contract With Fields 2.pdf",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
}]
**Update: Complete JSON
Looking to add a second **document****
{
"emailBlurb": "Test Blurb",
"emailSubject": "Test subject",
"status": "sent",
"compositeTemplates": [
{
"compositeTemplateId": "1",
"inlineTemplates": [
{
"sequence": "1","documents": [
{
"documentBase64": "'.$documentHashpdf.'",
"documentId": "2",
"name": "Not working", "order": "2"
}
],
"recipients": {
"signers": [
{
"email": "*******",
"name": "********e",
"recipientId": "1",
"smsAuthentication": {
"senderProvidedNumbers": ["******"]
},
"idCheckConfigurationName": "SMS Auth $",
"requireIdLookup": "true",
"clientUserId": "1001",
"defaultRecipient": "true",
"tabs": {
"signHereTabs": [
{
"pageNumber": "1",
"documentId": "1",
"tabLabel": "text 1",
"recipientId": "1"
}
],
"fullNameTabs": [
{
"pageNumber": "1",
"documentId": "1",
"xPosition": "20",
"yPosition": "20",
"height": "10",
"width": "20",
"tabLabel": "Text 2",
"recipientId": "1"
}
],
"dateSignedTabs": [
{
"pageNumber": "1",
"documentId": "1",
"xPosition": "20",
"yPosition": "30",
"height": "10",
"width": "20",
"tabLabel": "text 3",
"recipientId": "1"
}
]
}
}
]
}
}
],
"document": {
"documentId": "1",
"name": "Working",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
} }
]
There are 3 "models" for constructing envelopes. I recommend using composite templates in the intended way, where you manage each document contribution to the envelope by enclosing within separate compositeTemplate elements. I reworked your JSON like this:
{
"emailBlurb": "Test Blurb",
"emailSubject": "Test subject",
"status": "sent",
"compositeTemplates": [{
"compositeTemplateId": "1",
"document": {
"documentId": "1",
"name": "Working",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
},
"inlineTemplates": [{
"sequence": "1",
"recipients": {
"signers": [{
"email": "*******",
"name": "********e",
"recipientId": "1",
"smsAuthentication": {
"senderProvidedNumbers": ["******"]
},
"idCheckConfigurationName": "SMS Auth $",
"requireIdLookup": "true",
"clientUserId": "1001",
"defaultRecipient": "true"
}]
}
}]
},
{
"compositeTemplateId": "2",
"document": {
"documentBase64": "'.$documentHashpdf.'",
"documentId": "2",
"name": "Not working",
"transformPdfFields": "true"
},
"inlineTemplates": [{
"sequence": "1",
"recipients": {
"signers": [{
"email": "*******",
"name": "********e",
"recipientId": "1",
"smsAuthentication": {
"senderProvidedNumbers": ["******"]
},
"idCheckConfigurationName": "SMS Auth $",
"requireIdLookup": "true",
"clientUserId": "1001",
"defaultRecipient": "true"
}]
}
}]
}
]
}
In this fashion, any number of additional documents you wish to add would simply be another compositeTemplate element added to the array. This works for additional documents regardless of whether you wish to transform PDF fields, documents sourced from DocuSign templates, or any additional document for which you want to apply a template to overlay.
Note that the use of compositeTemplateId is only needed to relate multipart form attachments, which is a cleaner way to handle your documents rather than base64 encoding them in documentBase64 elements.
Here is the fixed JSON:
{
"emailBlurb": "Test Blurb",
"emailSubject": "Test subject",
"status": "sent",
"compositeTemplates": [
{
"compositeTemplateId": "1",
"inlineTemplates": [
{
"sequence": "1","documents": [
{
"documentBase64": "'.$documentHashpdf.'",
"documentId": "2",
"name": "Not working", "order": "2"
}
],
"recipients": {
"signers": [
{
"email": "*******",
"name": "********e",
"recipientId": "1",
"smsAuthentication": {
"senderProvidedNumbers": ["******"]
},
"idCheckConfigurationName": "SMS Auth $",
"requireIdLookup": "true",
"clientUserId": "1001",
"defaultRecipient": "true",
"tabs": {
"signHereTabs": [
{
"pageNumber": "1",
"documentId": "1",
"tabLabel": "text 1",
"recipientId": "1"
}
],
"fullNameTabs": [
{
"pageNumber": "1",
"documentId": "1",
"xPosition": "20",
"yPosition": "20",
"height": "10",
"width": "20",
"tabLabel": "Text 2",
"recipientId": "1"
}
],
"dateSignedTabs": [
{
"pageNumber": "1",
"documentId": "1",
"xPosition": "20",
"yPosition": "30",
"height": "10",
"width": "20",
"tabLabel": "text 3",
"recipientId": "1"
}
]
}
}
]
}
},
{
"documentId": "1",
"name": "Working",
"transformPdfFields": "true",
"documentBase64": "'.$documentHashpdf.'"
}
]}
]
}

DocuSign API yields CANNOT_EXCLUDE_DOCUMENT error

We have had code using the DocuSign C# API in production for well over a year now, including some that successfully excludes documents from some recipients but not others. Now, on a new envelope type, I am getting the above error and can't figure out why. Below are the lightly edited/anonymized JSON request payload and DocuSign response with the error (both captured with Fiddler).
As you can see, there are three documents and two signers, with both signers getting document id 1, and one signer being excluded from document id 2 and the other signer excluded from document id 3. There are also two carbon copy recipients who are both internal employees on our account. For what it's worth, the Document Visibility setting on the account is "Must sign to view, unless a member of sender's account."
Here is the JSON payload being sent to DocuSign to create the envelope:
{
"documents": [
{
"documentId": "1",
"name": "Document1",
"fileExtension": "pdf",
"order": "1",
"documentBase64": "blahblahblah"
},
{
"documentId": "2",
"name": "Document2",
"fileExtension": "pdf",
"order": "2",
"documentBase64": "blahblahblah"
},
{
"documentId": "3",
"name": "Document2",
"fileExtension": "pdf",
"order": "3",
"documentBase64": "blahblahblah"
}
],
"recipients": {
"signers": [
{
"tabs": {
"signHereTabs": [
{
"name": "Joe Smith",
"tabLabel": "Signature1",
"scaleValue": "0.9",
"documentId": "1",
"recipientId": "1",
"anchorString": "Some anchor text",
"anchorXOffset": "4",
"anchorYOffset": "46",
"anchorMatchWholeWord": "true",
"tabId": "Signature1"
},
{
"name": "Joe Smith",
"tabLabel": "Signature2",
"documentId": "2",
"recipientId": "1",
"anchorString": "Some other anchor text",
"anchorXOffset": "4",
"anchorYOffset": "67",
"anchorMatchWholeWord": "true",
"tabId": "Signature2"
}
],
"dateSignedTabs": [
{
"tabLabel": "DateSigned1",
"documentId": "1",
"recipientId": "1",
"anchorString": "Some anchor text",
"anchorXOffset": "175",
"anchorYOffset": "38",
"anchorMatchWholeWord": "true",
"tabId": "DateSigned1"
}
],
"textTabs": []
},
"recipientSuppliesTabs": "false",
"excludedDocuments": [ "3" ],
"name": "Joe Smith",
"email": "joesmith#example.com",
"emailRecipientPostSigningURL": "https://www.foocorp.com/e-consent-complete/",
"recipientId": "1",
"customFields": [],
"routingOrder": "1",
"roleName": "Signer",
"emailNotification": {
"emailSubject": "Joe Smith has documents from Foo Corp",
"emailBody": "Blah blah blah"
}
},
{
"tabs": {
"signHereTabs": [
{
"name": "Bob Jones",
"tabLabel": "Signature1",
"scaleValue": "0.9",
"documentId": "1",
"recipientId": "2",
"anchorString": "Some anchor text",
"anchorXOffset": "277",
"anchorYOffset": "46",
"anchorMatchWholeWord": "true",
"tabId": "Signature1"
},
{
"name": "Bob Jones",
"tabLabel": "Signature3",
"documentId": "3",
"recipientId": "2",
"anchorString": "Some other anchor text",
"anchorXOffset": "4",
"anchorYOffset": "67",
"anchorMatchWholeWord": "true",
"tabId": "Signature3"
}
],
"dateSignedTabs": [
{
"tabLabel": "DateSigned1",
"documentId": "1",
"recipientId": "2",
"anchorString": "Some anchor text",
"anchorXOffset": "448",
"anchorYOffset": "38",
"anchorMatchWholeWord": "true",
"tabId": "DateSigned1"
}
],
"textTabs": []
},
"recipientSuppliesTabs": "false",
"excludedDocuments": [ "2" ],
"name": "Bob Jones",
"email": "bobjones#example.com",
"emailRecipientPostSigningURL": "https://www.foocorp.com/e-consent-complete/",
"recipientId": "2",
"customFields": [],
"routingOrder": "1",
"roleName": "Signer",
"emailNotification": {
"emailSubject": "Bob Jones has documents from Foo Corp",
"emailBody": "Blah blah blah"
}
}
],
"carbonCopies": [
{
"name": "Sue Employee",
"email": "sue#foocorp.com",
"emailRecipientPostSigningURL": "https://www.foocorp.com/e-consent-complete/",
"recipientId": "3",
"customFields": [],
"routingOrder": "1",
"roleName": "Internal",
"emailNotification": {
"emailSubject": "Joe Smith has documents from Foo Corp",
"emailBody": "Blah blah blah"
}
},
{
"name": "Sam Employee",
"email": "sam#foocorp.com",
"emailRecipientPostSigningURL": "https://www.foocorp.com/e-consent-complete/",
"recipientId": "4",
"customFields": [],
"routingOrder": "1",
"roleName": "Internal",
"emailNotification": {
"emailSubject": "Joe Smith has documents from Foo Corp",
"emailBody": "Blah blah blah"
}
}
],
"certifiedDeliveries": []
},
"status": "created",
"emailSubject": "Joe Smith has documents from Foo Corp",
"emailBlurb": "Blah blah blah",
"allowMarkup": "false",
"allowReassign": "false",
"recipientsLock": "true",
"emailSettings": {
"replyEmailAddressOverride": "sue#foocorp.com",
"replyEmailNameOverride": "Sue Employee"
}
}
And here is the HTTP response:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Content-Length: 177
Content-Type: application/json; charset=utf-8
X-RateLimit-Reset: 1519927200
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 997
X-DocuSign-TraceToken: deadbeef-dead-beef-dead-beefdeadbeef
Date: Thu, 01 Mar 2018 17:25:01 GMT
Strict-Transport-Security: max-age=31536000; includeSubDomains
{
"errorCode": "CANNOT_EXCLUDE_DOCUMENT",
"message": "This document cannot be excluded for this recipient. Recipient: Joe Smith cannot be excluded from Document:"
}
Any direction appreciated.
Edited to show that the excluded documents both share the same name because it's a "logical name" to me, e.g., "W9" that I use in combination with custom fields on the document to then route to the right place in doc management when it comes back via a Connect call. If I send document id 2 and 3 with different names, then it all works. But exclusions work by document id, not document name, so why would that matter?
Edit #2: I was able to prove to myself that it doesn't matter what the document name is - whether they're the same or different, I get the error.
When you use Anchor string then DocuSign searches for that anchor string on complete envelope and anchors are not at document scope instead anchors are on envelope scope. So if you have same two documents added into the envelope then DocuSign will find the anchor string in both the documents and will assign DS Tabs on both documents to the recipients. Now since you are using same documents twice, so DS Tabs from both documents will be assigned to the recipient and excludedDocuments will not make sense in this scenario.

Docusign : create envelope with recipient custom field

I'm trying to create an envelope based on a template and assign a custom field to one of the recipients ("customFields": ["5616999"] , which is the employee ID).
This is my POST REST API:
URI : https://demo.docusign.net/restapi/v2/accounts/{accountid}/envelopes
Payload:
{ "status":"sent",
"emailSubject": "Test with template and custom field",
"templateId": "447e6671-74d1-45ce-bf3b-aa7a5c235ea5", "documents": [{ "documentId": "25407849", "name": "testTemplateDoc2.pdf", "documentBase64": " my base64 string of the document"}],
"templateRoles": [{
"email": "test#gmail.com",
"name": "john doe",
"recipientId": "10501840",
"roleName": "RH",
"routingOrder": "1",
"emailNotification": {
"emailBody": "text12808",
"emailSubject": "Signez ce document [[Collaborateur_UserName]]",
"supportedLanguage": "fr"
},
"recipientSignatureProviders": [{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"signatureProviderOptions": {
"sms": "+33265555555"
}
}
],
"tabs": {
"signHereTabs": [{
"anchorString": "/RH1/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0",
"name": "Please sign here",
"optional": "false",
"recipientId": "10501840",
"scaleValue": 1
}
]
}
}, {
"email": "test2#gmail.com",
"name": "jane doe",
"recipientId": "61432066",
"roleName": "Collaborateur",
"routingOrder": "2",
"emailNotification": {
"emailBody": "text2 2808",
"emailSubject": "Signez votre document Mr. [[Collaborateur_UserName]]",
"supportedLanguage": "fr"
},
"recipientSignatureProviders": [{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"signatureProviderOptions": {
"oneTimePassword": "1234"
}
}
],
"tabs": {
"signHereTabs": [{
"anchorString": "/S1/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0",
"name": "Please sign here",
"optional": "false",
"recipientId": "61432066",
"scaleValue": 1
}
]
},
"customFields": ["5616999"]
}, {
"email": "test3#gmail.com",
"name": "john3 doe3",
"recipientId": "64377607",
"roleName": "Directeur",
"routingOrder": "3",
"emailNotification": {
"emailBody": "text3 2808",
"emailSubject": "consultez le document de Mr. [[Collaborateur_UserName]]",
"supportedLanguage": "fr"
},
"recipientSignatureProviders": [{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"signatureProviderOptions": {
"oneTimePassword": "1234"
}
}
]
}
]
}
SO I got a 200 OK and my envelope was created successfully, however the recipient custom field does not appear when I do a simple GET on the envelope.
I think it's not taken into account.
This is my GET URI
https://demo.docusign.net/restapi/v2/accounts/{accountID}/envelopes/{envelopeid}/recipients?include_extended=true&include_tabs=true
this is the result :
{
"signers": [
{
"tabs": {
"signHereTabs": [
{
"stampType": "signature",
"name": "Please sign here",
"tabLabel": "Sign Here",
"scaleValue": 1,
"optional": "false",
"documentId": "1",
"recipientId": "1",
"pageNumber": "1",
"xPosition": "69",
"yPosition": "688",
"anchorString": "/RH1/",
"anchorXOffset": "0",
"anchorYOffset": "0",
"anchorUnits": "pixels",
"tabId": "a3c9e24a-054c-4e39-bb85-ff602c9afd15"
}
]
},
"signInEachLocation": "false",
"creationReason": "sender",
"isBulkRecipient": "false",
"recipientSignatureProviders": [
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"signatureProviderOptions": {
"sms": "+330642037079"
}
}
],
"name": "john doe",
"email": "test#gmail.com",
"recipientId": "1",
"recipientIdGuid": "77e97f08-552e-4e5b-ab0d-1802d72813cf",
"requireIdLookup": "false",
"userId": "0358b4e5-2c64-4d37-a6c2-d9f099ff5071",
"routingOrder": "1",
"note": "",
"roleName": "RH",
"status": "created",
"deliveryMethod": "email",
"templateLocked": "false",
"templateRequired": "false",
"emailNotification": {
"emailSubject": "[BPMED] Signez ce document [[Collaborateur_UserName]]",
"emailBody": "text12808",
"supportedLanguage": "fr"
},
"totalTabCount": "1"
},
{
"tabs": {
"signHereTabs": [
{
"stampType": "signature",
"name": "Please sign here",
"tabLabel": "Sign Here",
"scaleValue": 1,
"optional": "false",
"documentId": "1",
"recipientId": "2",
"pageNumber": "1",
"xPosition": "69",
"yPosition": "264",
"anchorString": "/S1/",
"anchorXOffset": "0",
"anchorYOffset": "0",
"anchorUnits": "pixels",
"tabId": "5bf64798-f22a-4f08-9bfd-da5745c1c0a0"
}
]
},
"signInEachLocation": "false",
"creationReason": "sender",
"isBulkRecipient": "false",
"recipientSignatureProviders": [
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"signatureProviderOptions": {
"oneTimePassword": "1234"
}
}
],
"name": "jane doe",
"email": "test2#gmail.com",
"recipientId": "2",
"recipientIdGuid": "c3de6e46-be6a-4ccf-b939-30c0cd251849",
"requireIdLookup": "false",
"userId": "e0a726f8-a89d-4b86-99fc-153150cd4892",
"routingOrder": "2",
"note": "",
"roleName": "Collaborateur",
"status": "created",
"deliveryMethod": "email",
"templateLocked": "false",
"templateRequired": "false",
"emailNotification": {
"emailSubject": "[BPMED] Signez votre document Mr. [[Collaborateur_UserName]]",
"emailBody": "text2 2808",
"supportedLanguage": "fr"
},
"totalTabCount": "2"
}
],
"agents": [],
"editors": [],
"intermediaries": [],
"carbonCopies": [],
"certifiedDeliveries": [
{
"name": "john3 doe3",
"email": "test3#gmail.com",
"recipientId": "3",
"recipientIdGuid": "b9569f7c-996d-4549-88f6-1e05e9b96ea7",
"requireIdLookup": "false",
"userId": "6f0b5463-3baa-4607-bcc9-1958873c12e2",
"routingOrder": "3",
"note": "",
"roleName": "Directeur",
"status": "created",
"templateLocked": "false",
"templateRequired": "false",
"emailNotification": {
"emailSubject": " consultez le document de Mr. [[Collaborateur_UserName]]",
"emailBody": " text3 2808",
"supportedLanguage": "fr"
},
"totalTabCount": "0"
}
],
"inPersonSigners": [],
"recipientCount": "3"
}
I've tried creating the envelope in draft mode and then making a PUT request to add the custom field, but it didn't work either...
PS: I've successfully created envelopes with recipient custom fields (not based on a template) and it was ok and the recipient custom field was well integrated in the envelope.
You can use DocuSign compositeTemplates and specify the recipient custom fields. Here is an example. templateRoles does not support specifying recipient custom fields
{
"emailSubject": "Test with template and custom field",
"status": "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": "1",
"templateId": "447e6671-74d1-45ce-bf3b-aa7a5c235ea5"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test#gmail.com",
"name": "john doe",
"recipientId": "10501840",
"roleName": "RH",
"routingOrder": "1",
"customFields": [ "5616999" ],
"tabs": { },
"emailNotification": { },
"recipientSignatureProviders": { }
}
]
}
}
],
"document": {
"documentId": "25407849",
"name": "testTemplateDoc2.pdf",
"fileExtension": "pdf",
"documentBase64": ""
}
}
]
}

SalesForce DocuSign REST API createAndSendenvelope

Can anyone give a sample apex code REST API example for createAndSendenvelope. I am using demo DocuSign sandbox and I get INCOMPLETE ENVELOPE error. I do have all the required elements in my envelope, so looking to see what I am missing or if I am not creating it in a correct manner. Below is the json that I pass as request and I get response: "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Content-Type does not contain boundary parameter."
--BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status": "created",
"recipients": {
"signers": [{
"tabs": {
"signHeretabs": [{
"yPosition": "15",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"recipientId": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentid": "1",
"anchorYoffset": null,
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Sign Here",
"anchorIgnoreIfNotPresent": "true"
}],
"initialsTabs": [{
"yPosition": "45",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"receipientId": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentId": "1",
"anchorYoffset": null,
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Initials Here",
"anchorIgnoreIfNotPresent": "true"
}],
"dateSignedTabs": [{
"yPosition": "65",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"receipientid": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentid": "1",
"anchorYoffset": "-5",
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Date Signed",
"anchorIgnoreIfNotPresent": "true"
}]
},
"routingorder": "1",
"rolename": "First Signer",
"recipientid": "1",
"name": "Marisol L Testcase",
"email": "testfd1#gcpa.com"
}]
},
"emailsubject": "TestDocuSign Call",
"emailBlurb": "Test Email Blurb",
"documents": [{
"name": "Name1",
"fileExtension": ".txt",
"documentId": "1",
"documentBase64": null
}]
}
--BOUNDARY
Content-Type: application/octet-stream
Content-Disposition: file; filename="Name1"; documentid=1
Content-Transfer-Encoding: base64
VGhpcyBpcyBhIHNhbXBsZSBmaWxlIHVwbG9hZCBmb3IgdGVzdGluZy4=
--BOUNDARY--
Update: I could get rid of the boundary parameter error and now get "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Envelope definition missing."
You should not put "documentBase64": null in the "documents" node as you are already passing document as multipart request and "fileExtension" should be "txt" not ".txt". Now coming to the tabs assignment, you are mixing two strategies, one is X/Y position and another is Anchor String. You should use one of them, X/Y position will put a DocuSign tab at specified X/Y position, whereas AnchorString will try to find the that string in the document and if it finds then attaches the DocuSign tab on it. And there is no fall back strategy, means if anchor string is not available then put X/Y position, this is not possible. So either your document should have anchor string then use Anchor String strategy else, remove Anchor string related property from JSON and place tags as per X/Y position.

Resources