问题
I have a client that signs into their DS account, uploads a single 17-page PDF, clicks the action link to the side and selects "Apply Template". The template contains tabs and roles. They fill in the roles in the DS UI and click send. I am attempting to rebuild that process via API.
I found this that looks like it should work for exactly my scenario: How do I apply a template to a document using Docusign REST API
I am getting an envelope with 34 pages instead: the original 17-page uploaded PDF and the 17 pages from the template. The template is being added vs. applied.
The template does have its documents split out (e.g., a 4 page document with two tabs, a 1 page document with 1 tab, etc. total 17 pages). It works great through the UI so not sure if this affects anything.
How do I upload the PDF and apply the template to the document?
Here is my request payload:
POST https://demo.docusign.net/restapi/v2/accounts/ACCTNMBR/envelopes HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data; boundary=myboundary
--myboundary
Content-Type: application/json
Content-Disposition: form-data
{
"emailBlurb": "Test Envelope Blurb",
"emailSubject": "Test Envelope Subject",
"status": "created",
"signingLocation": "Online",
"compositeTemplates": [
{
"document": {
"documentId": 1,
"name": "UPLOADED.pdf"
},
"inlineTemplates": [{
"sequence": "1",
"recipients": {
"signers": [{
"email": "jane.doe@example.com",
"name": "Jane Doe",
"recipientId": "1",
"roleName": "Signer1",
"clientUserId": "123"
}]
}
}]
},
{
"serverTemplates": [{
"sequence": "1",
"templateId": "TEMPLATE_ID"
}]
}]
}
--myboundary
Content-Type: application/pdf
Content-Disposition: file; filename="UPLOADED.pdf"; documentid=1
PDF_BYTES_HERE
--myboundary--
回答1:
The request you posted is creating two composite templates. The first has your uploaded PDF and defines your signer while the second pulls in the content of your server-side template. The solution is to define just one composite template. This will cause your uploaded PDF, inline template, and server-side template to all be merged. E.g.:
POST https://demo.docusign.net/restapi/v2/accounts/ACCTNMBR/envelopes HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data; boundary=myboundary
--myboundary
Content-Type: application/json
Content-Disposition: form-data
{
"emailBlurb": "Test Envelope Blurb",
"emailSubject": "Test Envelope Subject",
"status": "created",
"signingLocation": "Online",
"compositeTemplates": [
{
"document": {
"documentId": 1,
"name": "UPLOADED.pdf"
},
"inlineTemplates": [{
"sequence": "1",
"recipients": {
"signers": [{
"email": "jane.doe@example.com",
"name": "Jane Doe",
"recipientId": "1",
"roleName": "Signer1",
"clientUserId": "123"
}]
}
}],
"serverTemplates": [{
"sequence": "2",
"templateId": "TEMPLATE_ID"
}]
}]
}
--myboundary
Content-Type: application/pdf
Content-Disposition: file; filename="UPLOADED.pdf"; documentid=1
PDF_BYTES_HERE
--myboundary--
A couple things to watch out for though:
- First document wins - lower sequence templates contribute documents.
- Last recipients/tabs win - higher sequence templates override recipients/tabs.
- If your server-side template has multiple documents then you'll probably need multiple documents to be uploaded. If you intend to upload one PDF then your server-side template should have a single document as well.
回答2:
The end answer was to create an envelope with the uploaded document in draft form. Then apply a template to the document of the envelope instead of to the envelope itself or using composite templates.
POST https://demo.docusign.net/restapi/v2/accounts/ACCTNMBR/envelopes/ENVELOPEID/documents/1/templates HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"documentTemplates": [{
"documentId": "1",
"templateId": "TEMPLATE_ID",
"documentStartPage": "1",
"documentEndPage": "15"
}]
}
来源:https://stackoverflow.com/questions/32793665/how-do-i-apply-a-server-template-to-envelope-document-in-docusign-api