Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

docusignapi - Adding documents to envelopes using composite templates in DocuSign

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": "[email protected]",
                            "name": "test1",
                            "recipientId": "1",
                            "routingOrder": "1",
                            "roleName": "Client 1"
                        },
                        {
                            "email": "[email protected]",
                            "name": "test2",
                            "recipientId": "2",
                            "routingOrder": "2",
                            "roleName": "Client 2"
                        }
                    ],
                    "documents": [
                        {
                            "transformPdfFields": "false",
                            "name": "test0.pdf",
                            "documentId": "1"
                        }
                    ]
                }
            }
        ]
    },
    {
        "inlineTemplates": [
            {
                "sequence": "1",
                "recipients": {
                    "signers": [
                        {
                            "email": "[email protected]",
                            "name": "test1",
                            "recipientId": "1",
                            "routingOrder": "1",
                            "roleName": "Client 1"
                        },
                        {
                            "email": "[email protected]",
                            "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": "[email protected]",
            "name": "test1",
            "recipientId": "1",
            "clientUserId": "1",
            "signerName": "test1",
            "defaultRecipient": "true",
            "defaultRecipientSpecified": "true",
            "routingOrder": "1"
        },
        {
            "email": "[email protected]",
            "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": "[email protected]",    
            "name": "test1",             
            "recipientId": "1"                
        },                              
        {                              
            "email": "[email protected]",  
            "name": "test2",         
            "recipientId": "2"              
        }                            
        ],                           
        "document":                  
        {                            
            "name": "test0",              
            "documentId": "1",            
            "fileExtension": "pdf"         
        }                               
    }                  
}                  
]               
},               
{                
"inlineTemplates": [   
{                     
    "sequence": "2",       
    "recipients": {         
    "signers": [            
        {                        
            "email": "[email protected]",   
            "name": "test1",          
            "recipientId": "1"
        },
        {                              
            "email": "[email protected]",  
            "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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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": "[email protected]",
                    "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--

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...