使用DocuSign中的复合模板将文档添加到信封中

时间:2013-11-18 17:48:22

标签: docusignapi docusigncompositetmplts

我尝试使用docusign api将文档添加到复合模板中,并且文档不会像我期望的那样加载到信封中。我目前让我的代码使用测试json,我在不使用复合模板的情况下添加文档,它完美地运行。然而,似乎复合模板跳过了文档。以下是我创建它的方式:

{
"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"
                        }
                    ]
                }
            }
        ]
    }
]

}

这是一个小小的考验我这样做我明白这是不切实际的。但我试图理解的是为什么这不会将文件添加到信封中。以下请求执行我上面尝试的操作。

{
"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"
        }
    ]
}

}

有人知道为什么复合模板的信封不能加载文件吗?

提前谢谢!

更新

这是我对复合模板的要求:

--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--

我已将我的文档调整为使用name和fileDxtension,因此我在fileName上省略了.pdf扩展名,因为这似乎是实现此目的的另一种方法。我已经尝试过两种方式而且没有运气。

1 个答案:

答案 0 :(得分:4)

在您发布的请求JSON中,您指定“文档”(复数)作为文档对象的集合/数组 - 这是不正确的。 compositeTemplates 数组中的每个Composite Template项目最多只能包含一个单个文档。这意味着用于在复合模板中指定文档的JSON语法如下:

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

文档是单数,它是一个对象(不是对象数组)。 “复合模板”JSON请求的完整请求语法显示在您之前问题的答案中:
How do I apply a template to a document using Docusign REST API

重新提问您的“更新”:

在您在“更新”下发布的请求的JSON部分中,我注意到您已在收件人对象(包含其中)中包含文档 inlineTemplates 对象中 - 这不是文档的正确位置。将您的JSON结构与以下(正确)结构进行密切比较,并相应地调整您的请求。从本质上讲,文档必须是 inlineTemplates 的同行 - 不在 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--