使用COMPOSITE模板时,在docusign API中出现未指定的错误

时间:2014-05-10 01:11:46

标签: docusignapi docusigncompositetmplts

您好我正在尝试使用COMPOSITE模板来制作一个模板并在创建信封时添加文档。

完整的请求如下。

但是我得到" UNSPECIFIED_ERROR"如下

我是新手使用docusign和复合模板API。

如果有人在参考有关复合模板的在线资料后尝试了请求,可能会指出错误。

感谢阅读!!!

响应:

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

2 个答案:

答案 0 :(得分:2)

请求中的每个 compositeTemplate 对象都必须同时指定:

  • 文档 - 通过 serverTemplate 或通过独立定义 文档指定为请求的一部分

  • 收件人

例如,以下多部分请求将创建一个包含服务器模板中的文档的信封,后跟请求中指定的其他文档:

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

如果我希望附加文档首先出现在信封中,我只需在请求中交换 compositeTemplate 对象的顺序,以便在服务器模板之前指定文档:

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

根据您在问题中发布的代码,我怀疑错误是由请求中的第二个 compositeTemplate 对象未指定收件人这一事实引起的。

最后,还有一些评论:

  • 确保您指定的收件人信息(email,name,recipientId)与所有复合模板对象完全匹配。
  • 如果您使用多部分请求创建信封(如上例所示),请密切注意换行符 - 它们必须完全按照示例中所示进行。
  • 虽然可以使用多部分请求来创建包含您指定为请求一部分的文档的信封(如上面的示例所示),但这样做更简单/更简单将使用“正常”(即非多部分)请求,您只需在文档中指定 base-64-encoded 文档字节对象本身,通过使用 documentBase64 属性 - 这消除了对多部分请求的需要。请参阅https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#REST API参考/文档参数.htm?突出显示= documentbase64。

答案 1 :(得分:1)

我想知道这是否与您提供的内联文档有关。我看到您指定了文档名称,但没有documentId,这可能导致错误,因为它可能默认为documentId = 1,这很可能是服务器模板文档使用的。

尝试这样的事情:

"document": {
    "name": "body.pdf",
    "documentId": "2"
}