I've been working on integrating the DocuSign REST API into my company's app. Things are mostly working, but there is still one problem. If I upload multiple (>= 2) documents, each with an associated server template, then all of the templates end up getting applied to the first document.
For example, the following API call to /accounts/account_id/envelopes
should upload two documents: document1.pdf
(7 pages) and document2.pdf
(2 pages). document1.pdf
's server template has a sign-here field on the 7th page and document2.pdf
's server template has a sign-here field on the 2nd page.
What appears on the DocuSign website is an envelope with the two documents correctly uploaded, but with document2.pdf
's sign-here field appearing on page 2 of document1.pdf
. If I manually remove and reapply the template on document2.pdf
, then the field gets correctly placed. I suspect this is due to a subtle problem with my sequence
attributes, but I have been unable to figure out exactly what is wrong.
{
"allowReassign": false,
"emailBlurb": "email text",
"emailSubject": "subject",
"status": "created",
"compositeTemplates": [
{
"document": {
"name": "document1.pdf",
"documentId": "1"
},
"serverTemplates": [
{
"sequence": "1",
"templateId": "12345678-abcd-1234-abcd-1234567890ab"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"name": "Test Primary",
"email": "test@example.com",
"recipientId": "1",
"routingOrder": "1",
"roleName": "RoleOne"
}
]
}
}
]
},
{
"document": {
"name": "document2.pdf",
"documentId": "2"
},
"serverTemplates": [
{
"sequence": "2",
"templateId": "abcdef12-1234-abcd-1234-abcdef123456"
}
],
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"name": "Test Primary",
"email": "test@example.com",
"recipientId": "1",
"routingOrder": "1",
"roleName": "RoleOne"
}
]
}
}
]
}
]
}
This issue in this example is not the sequence. It is the documentId's for the documents passed in.
When a server side template is created, think of it as having documentId=1. In this case, two server side templates are used, one for each composite template section and each has documentId=1. Tabs placed on these template documents are associated with documentId=1. The documentId of the document passed for each composite template in should also be documentId=1 so when that document overlays, the ID matches.
The example sets the second document passed in as documentId=2. So, when the envelope/template info is folded together, the tabs retain the association with documentId=1, so they appear on page 2 and page 7 of the first document, The second template is overlaid with documentId 2, so it will not have any tabs.
If the passed-in document for both composite templates uses documentId=1, the tabs will properly associate within each composite template, and then the documentID's will be reordered in the final envelope along with tab Id’s.
The sequence numbers can be 1,2,3,4 or 1,2 in the first composite template, and 1,2 in the second.
Working example:
POST http://localhost/restapi/v2/accounts/2/envelopes
X-DocuSign-Authentication: [omitted]
Accept: application/json
Content-Type: multipart/form-data; boundary=70fcb373-f40d-40bb-bddb-204fe789087f
X-DocuSign-ClientTransactionId: T635316112162595227
--70fcb373-f40d-40bb-bddb-204fe789087f
Content-Type: application/json
Content-Disposition: form-data
{
"compositeTemplates": [
{
"compositeTemplateId": "1",
"serverTemplates": [
{
"sequence": "1",
"templateId": "99B09A06-95AF-47A5-964B-A58E78B981DF"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"name": "Resty Tester",
"email": "resty.tester@gmail.com",
"recipientId": "1",
"routingOrder": "1",
"roleName": "RoleOne"
}
]
}
}
],
"document": {
"documentId": "1",
"name": "document1In.pdf"
}
},
{
"compositeTemplateId": "2",
"serverTemplates": [
{
"sequence": "2",
"templateId": "36FD0433-AAE0-43A7-B795-E06738159A59"
}
],
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"name": "Resty Tester",
"email": "resty.tester@gmail.com",
"recipientId": "1",
"routingOrder": "1",
"roleName": "RoleOne"
}
]
}
}
],
"document": {
"documentId": "1",
"name": "document2In.pdf"
}
}
],
"status": "created",
"emailSubject": "Subject PostCompositeTemplate_PLAT_1647_20140328014654",
"emailBlurb": "Blurb PostCompositeTemplate_PLAT_1647_20140328014654",
"allowReassign": "false"
}
--70fcb373-f40d-40bb-bddb-204fe789087f
Content-Type: application/pdf
Content-Disposition: file; filename="document1In.pdf"; documentId=1; compositeTemplateId="1"
Content-Transfer-Encoding: base64
[bytes omitted]
--70fcb373-f40d-40bb-bddb-204fe789087f
Content-Type: application/pdf
Content-Disposition: file; filename="document2In.pdf"; documentId=1; compositeTemplateId="2"
Content-Transfer-Encoding: base64
[bytes omitted]
--70fcb373-f40d-40bb-bddb-204fe789087f--
201 Created
Pragma: no-cache
X-DocuSign-ClientTransactionId: T635316112162595227
Content-Length: 198
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Fri, 28 Mar 2014 20:46:58 GMT
Expires: -1
{
"envelopeId": "5b28e38e-84c0-4af0-a3d0-e3c1e6cee17d",
"uri": "/envelopes/5b28e38e-84c0-4af0-a3d0-e3c1e6cee17d",
"statusDateTime": "2014-03-28T20:46:57.4300000Z",
"status": "created"
}
With regards to the sequence see my question here. The sequence number should denote the object sequence within the scope of the current composite template. I increment my seq# for the inline templates and it works fine. That being said, it may not be the issue with regards to the sig page being appended improperly. I'd start there, however. Hope this helps.
I've successfully repro'd the issue you describe, and have tried remedying the issue by using various combinations of sequence value, all to no avail. This seems like a bug to me.
来源:https://stackoverflow.com/questions/20152788/incorrectly-applied-server-templates-with-multiple-composite-templates