问题
Hi I am trying to use COMPOSITE template to club one template and add a document while creating envelope.
The complete request is below.
However i am getting "UNSPECIFIED_ERROR" as below
I am new to use docusign and composite template API.
It would be great if someone can point me the error as i tried the request after referring to online material about composite templates.
Thanks for reading!!!
RESPONSE:
{
errorCode: "UNSPECIFIED_ERROR"
message: "An item with the same key has already been added."
}
REQUEST
POST https://demo.docusign.net/restapi/v2/accounts/ACTID/envelopes HTTP/1.1
Host: demo.docusign.net
Connection: keep-alive
Content-Length: 6640
X-DocuSign-Authentication: <DocuSignCredentials><Username>username.com</Username><Password>PA$$W0RD</Password><IntegratorKey>INTG KEY</IntegratorKey></DocuSignCredentials>
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"accountId": "act_ID",
"brandId": "brnd_ID",
"status": "SENT",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": 1,
"templateId": "temp_ID_1"
}
],
"inlineTemplates": [
{
"sequence": 1,
"recipients": {
"signers": [
{
"name": "Signer Name",
"email": "signer@email.com",
"recipientId": "1",
"roleName": "signer",
"tabs": {
"textTabs": [
{
"tabLabel": "SignerRole",
"value": "signerRole"
},
{
"tabLabel": "SignerAddress",
"value": "test TT DEMO"
},
{
"tabLabel": "date",
"value": "05/10/2014"
}
]
}
}
],
"carbonCopies": [
{
"name": "CarbonCopyName",
"email": "carboncopy@emailcom",
"recipientId": "1",
"roleName": "carbonCopyRole"
}
]
}
}
]
},
{
"inlineTemplates": [
{
"sequence": 2,
"document": {
"name": "body.pdf"
}
}
]
}
]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="body.pdf"
%PDF-1.4
%????
2 0 obj
<<
--MY_BOUNDARY--
回答1:
Each individual compositeTemplate object in the request must specify both:
- document(s) -- either defined via serverTemplate(s) or via standalone document that's specified as part of the request
AND
- recipients
For example, the following multipart request will create an Envelope that contains the documents from the server Template, followed by the additional document that's specified in the request:
POST https://demo.docusign.net/restapi/v2/accounts/201105/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"username@test.com","Password":"mypassword","IntegratorKey":"ABCD-dbd5f342-d9f6-47c3-b293-xxxxxxxxxxxx"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 272956
Expect: 100-continue
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status" : "sent",
"emailSubject" : "Test Envelope Subject",
"emailBlurb" : "Test Envelope Blurb",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "TEMPLATE_ID"
}],
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [{
"email": "abbysemail@outlook.com",
"name": "Abby Abbott",
"recipientId": "1",
"roleName": "Initiator",
"routingOrder":"1"
}
]
}
}]
},
{
"inlineTemplates": [
{
"sequence" : 1,
"recipients": {
"signers" : [{
"email": "abbysemail@outlook.com",
"name": "Abby Abbott",
"recipientId": "1"
}]
}
}],
"document": {
"documentId": 1,
"name": "Customer Agreement",
"fileExtension": "pdf"
}
}
]}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="CustomerAgreement.pdf"; documentid="1"
PDF_BYTE_STREAM_HERE
--MY_BOUNDARY--
If I wanted the additional document to appear first in the envelope, I would simply swap the order of compositeTemplate objects in the request, so that the document is specified before the server template:
POST https://demo.docusign.net/restapi/v2/accounts/201105/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"username@test.com","Password":"mypassword","IntegratorKey":"ABCD-dbd5f342-d9f6-47c3-b293-xxxxxxxxxxxx"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 272956
Expect: 100-continue
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status" : "sent",
"emailSubject" : "Test Envelope Subject",
"emailBlurb" : "Test Envelope Blurb",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence" : 1,
"recipients": {
"signers" : [{
"email": "abbysemail@outlook.com",
"name": "Abby Abbott",
"recipientId": "1"
}]
}
}],
"document": {
"documentId": 1,
"name": "Customer Agreement",
"fileExtension": "pdf"
}
},
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "TEMPLATE_ID"
}],
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [{
"email": "abbysemail@outlook.com",
"name": "Abby Abbott",
"recipientId": "1",
"roleName": "Initiator",
"routingOrder":"1"
}
]
}
}]
}
]}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="CustomerAgreement.pdf"; documentid="1"
PDF_BYTE_STREAM_HERE
--MY_BOUNDARY--
Based on the code you've posted in your question, I'd suspect that the error is being caused by the fact that the second compositeTemplate object in the request does not specify recipients.
Finally, a few additional comments:
- Make sure that the recipient info (email, name, recipientId) you specify matches exactly across all composite template objects.
- If you use a multipart request to create the envelope (as shown in the above examples), pay close attention to line breaks -- they must occur exactly as shown in the examples.
- Although you can use a multipart request to create an envelope that contains document(s) you specify as part of the request (as the examples above show), an easier/simpler way to do so would be to use a "normal" (i.e., not multi-part) request whereby you simply specify base-64-encoded document bytes within the document object itself, by using the documentBase64 property -- which eliminates the need for the multipart request. See https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#REST API References/Document Parameters.htm?Highlight=documentbase64.
回答2:
I'm wondering if this is related to the inline document you're supplying. I see that you specify the document name but no documentId
and that might be causing the error as it probably defaults to documentId
= 1
, which is most likely in use by the server template document.
Try something like this:
"document": {
"name": "body.pdf",
"documentId": "2"
}
来源:https://stackoverflow.com/questions/23576146/getting-unspecified-error-in-docusign-api-while-using-composite-template