Adding documents to envelopes using composite templates in DocuSign

喜夏-厌秋 提交于 2019-11-26 18:34:10

问题


I'm trying to add documents to a composite template using the docusign api and the documents aren't loading into the envelope the way I would expect it to. I currently have my code working with a test json where I add documents without using composite templates and it works perfectly. It seems the composite templates skip right over the documents however. Here's how I'm creating it:

{
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status": "created",
"compositeTemplates": [
    {
        "inlineTemplates": [
            {
                "sequence": "1",
                "recipients": {
                    "signers": [
                        {
                            "email": "test1@yahoo.com",
                            "name": "test1",
                            "recipientId": "1",
                            "routingOrder": "1",
                            "roleName": "Client 1"
                        },
                        {
                            "email": "test2@gmail.com",
                            "name": "test2",
                            "recipientId": "2",
                            "routingOrder": "2",
                            "roleName": "Client 2"
                        }
                    ],
                    "documents": [
                        {
                            "transformPdfFields": "false",
                            "name": "test0.pdf",
                            "documentId": "1"
                        }
                    ]
                }
            }
        ]
    },
    {
        "inlineTemplates": [
            {
                "sequence": "1",
                "recipients": {
                    "signers": [
                        {
                            "email": "test1@yahoo.com",
                            "name": "test1",
                            "recipientId": "1",
                            "routingOrder": "1",
                            "roleName": "Client 1"
                        },
                        {
                            "email": "test2@gmail.com",
                            "name": "test2",
                            "recipientId": "2",
                            "routingOrder": "2",
                            "roleName": "Client 2"
                        }
                    ],
                    "documents": [
                        {
                            "transformPdfFields": "false",
                            "name": "test1.pdf",
                            "documentId": "2"
                        }
                    ]
                }
            }
        ]
    }
]

}

This is a little test I'm doing so I understand this is impractical. But what I'm trying to understand is why this wouldn't add documents to the envelope. The request below does what I'm trying to do above.

{
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status": "created",
"documents": [
    {
        "name": "test0.pdf",
        "documentId": "1"
    },
    {
        "name": "test1.pdf",
        "documentId": "2"
    },
    {
        "name": "test2.pdf",
        "documentId": "3"
    }
],
"recipients": {
    "signers": [
        {
            "email": "test1@yahoo.com",
            "name": "test1",
            "recipientId": "1",
            "clientUserId": "1",
            "signerName": "test1",
            "defaultRecipient": "true",
            "defaultRecipientSpecified": "true",
            "routingOrder": "1"
        },
        {
            "email": "test2@gmail.com",
            "name": "test2",
            "recipientId": "2",
            "clientUserId": "2",
            "signerName": "test2",
            "routingOrder": "2"
        }
    ]
}

}

Does anybody know why my envelope for the composite template won't load the documents?

Thank you in advance!

UPDATE:

Here's my request for the composite template:

--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{                
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status" : "created",               
"compositeTemplates": [               
{                    
"inlineTemplates": [  
{ 
    "sequence": "1",    
    "recipients": 
    {                           
        "signers": [                              
        {                              
            "email": "test1@yahoo.com",    
            "name": "test1",             
            "recipientId": "1"                
        },                              
        {                              
            "email": "test2@gmail.com",  
            "name": "test2",         
            "recipientId": "2"              
        }                            
        ],                           
        "document":                  
        {                            
            "name": "test0",              
            "documentId": "1",            
            "fileExtension": "pdf"         
        }                               
    }                  
}                  
]               
},               
{                
"inlineTemplates": [   
{                     
    "sequence": "2",       
    "recipients": {         
    "signers": [            
        {                        
            "email": "test1@yahoo.com",   
            "name": "test1",          
            "recipientId": "1"
        },
        {                              
            "email": "test3@yahoo.com",  
            "name": "test3",                           
            "recipientId": "2"                               
        }
    ],                  
    "document":                                 
        {    
            "name": "test1",                             
            "documentId": "2",                           
            "fileExtension": "pdf"                       
        }                                             
    }                  
}                  
]               
}               
]           
}
--MY_BOUNDARY

Content-Type: application/pdf
Content-Disposition: file; filename="test0.pdf"; documentid="1"

--MY_BOUNDARY

Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf"; documentid="2"




--MY_BOUNDARY--

I've adjusted my document to use name and fileDxtension, so I left out the .pdf extension on the fileName as that seems to be another method of implementing this. I've tried it both ways and had no luck.


回答1:


In the request JSON you posted, you're specifying "documents" (plural) as a collection/array of document objects -- which isn't correct. Each Composite Template item within the compositeTemplates array can only contain, at most, a single document. This means that the JSON syntax for specifying the document within a Composite Template is as follows:

"document": {
    "documentId": 1,
    "name": "test1.pdf"
}

i.e., document is singular, and it's an object (not an array of objects). Full request syntax of the 'composite templates' JSON request is shown in the answer of your prior question:
How do I apply a template to a document using Docusign REST API.

RE the "UPDATE" to your question:

In the JSON portion of the request that you've posted under "UPDATE", I notice that you have included document inside of the recipients object (which is contained within the inlineTemplates object) -- this is not the correct location for document. Compare your JSON structure closely with the following (correct) structure, and adjust your request accordingly. Essentially, document must be a peer of inlineTemplates -- not located within inlineTemplates.

POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNTNBR/envelopes HTTP/1.1

X-DocuSign-Authentication: {"Username":"USERNAME","Password":"PASSWORD","IntegratorKey":"INTEGRATORKEY"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 162100

--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": "CustomerAgreement",
            "fileExtension": "pdf"
        }
    }]
}

--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="CustomerAgreement.pdf"; documentid="1"

    <document bytes removed>

--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="Invoice.pdf"; documentid="2"

    <document bytes removed>

--MY_BOUNDARY--


来源:https://stackoverflow.com/questions/20054335/adding-documents-to-envelopes-using-composite-templates-in-docusign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!