DocuSign Rest API使用复合模板发送信封

时间:2016-07-23 15:32:01

标签: docusignapi nintex-workflow docusigncompositetmplts

我有一个复合模板,用于发送以下内容:

  1. 1份签名文件
  2. 另一份不需要签名但仍包含在内的文件
  3. 存储在模板中的文档
  4. 我收到此错误:执行网络请求时出错。 {  " errorCode":" UNSPECIFIED_ERROR",  " message":" Base-64字符数组或字符串的长度无效。"我已经确认Base64是4的倍数。我认为问题在于我没有正确的内容类型。我正在使用Nintex和SharePoint将Rest API发送给DocuSign。

    内容类型:multipart / form-data; boundary = MY_BOUNDARY

    Accept: application/json
    Host: na2.docusign.net
    
    
    --MY_BOUNDARY
    Content-Type: application/json
    Content-Disposition: form-data
    
    {
    "emailSubject": "Contract Package for {ItemProperty:Title}",
    "status" : "sent",
    "compositeTemplates": [
    {
    "inlineTemplates": [
        {
            "sequence" : 2,
            "recipients": {
                "signers" : [
                {
                    "email": "{WorkflowVariable:varCreatedByEmail}",
                    "name": "{WorkflowVariable:varCreatedByName}",
                    "recipientId": "1",
                    "roleName": "MI Employee",
                    "routingOrder": "1",
                    "tabs":
                        {"signerAttachmentTabs": [
                            {"anchorString": "/ea1/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Scope of Work Attachment",
                                "optional": "true",
                                "tabOrder": 1},
                            {"anchorString": "/ea2/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Pricing Attachment",
                                "optional": "true",
                                "tabOrder": 3}],
                        "textTabs":[
                            {"anchorString": "/ec1/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Scope of Work Text",
                                "disableAutoSize": true,
                                "width": 550,
                                "height": 220,
                                "tabOrder": 2},
                            {"anchorString": "/ec2/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Pricing Text",
                                "disableAutoSize": true,
                                "width": 550,
                                "height": 220,
                                "tabOrder": 4}]
                        }
                },
                {
                    "email": "{ItemProperty:E_x002d_Mail}",
                    "name": "{ItemProperty:Primary_x0020_Contact}",
                    "recipientId": "2",
                    "roleName": "Vendor",
                    "routingOrder": "2",
                    "tabs": 
                        {"fullNameTabs": [
                            {"anchorString": "/vn/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "signHereTabs":[
                            {"anchorString": "/vs/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "dateSignedTabs":[
                            {"anchorString": "/dvs/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "initialHereTabs":[
                            {"anchorString": "/vi/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "titleTabs":[
                            {"anchorString": "/vt/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "emailAddressTabs":[
                            {"anchorString": "/ve/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "textTabs":[
                            {"anchorString": "/va1/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Address Line 1"},
                            {"anchorString": "/va2/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Address Line 2",
                                "required": false},
                            {"anchorString": "/va3/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Address Line 3",},
                            {"anchorString": "/vc/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0",
                                "tabLabel": "Vendor Name",
                                "disableAutoSize": true,
                                "width": 225,
                                "height": 32}]
                        }   
                },
                {
                    "email": "{WorkflowVariable:varContractApproverEmail}",
                    "name": "{WorkflowVariable:varContractApproverName}",
                    "recipientId": "3",
                    "roleName": "MI Approver",
                    "routingOrder": "3",
                    "tabs":
                        {"signHereTabs":[
                            {"anchorString": "/as/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "dateSignedTabs":[
                            {"anchorString": "/das/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "fullNameTabs":[
                            {"anchorString": "/an/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "titleTabs":[
                            {"anchorString": "/at/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                    ,
                        "emailAddressTabs":[
                            {"anchorString": "/ae/",
                                "anchorXOffset": "1",
                                "anchorYOffset": "0"}]
                        }
                }           ]
                        }
        }               ],
        "document": {
            "documentId": 1,
            "name": "{WorkflowVariable:varContractName}",
            "documentbase64": "{WorkflowVariable:varContractBase64}"
        }
    },
    {
    "inlineTemplates": [
        {
            "sequence" : 3,
            "recipients": {
                "carbonCopies" : [
                {
                    "email": "{WorkflowVariable:varCreatedByEmail}",
                    "name": "{Common:InitiatorsDisplayName}",
                    "recipientId": "1",
                    "roleName": "MI Employee",
                    "routingOrder": "1"
                },
                {
                    "email": "{ItemProperty:E_x002d_Mail}",
                    "name": "{ItemProperty:Primary_x0020_Contact}",
                    "recipientId": "2",
                    "roleName": "Vendor",
                    "routingOrder": "2"
                },
                {
                    "email": "{WorkflowVariable:varContractApproverEmail}",
                    "name": "{WorkflowVariable:varContractApproverName}",
                    "recipientId": "3",
                    "roleName": "MI Approver",
                    "routingOrder": "3"
                }]
            }
        }],
        "document": {
            "documentId": 2,
            "name": "{WorkflowVariable:varExhibitAName}",
            "documentbase64": "{WorkflowVariable:varExhibitABase64}"
        }
    },
    {
        "serverTemplates": [
        {
            "sequence" : 6,
            "templateId": "D7472F81-46F9-4BEB-9017-DFAD3C0BCE83"
        }],
        "inlineTemplates": [
        {
            "sequence" : 7,
            "recipients": {
                "signers" : [{
                    "email": "{WorkflowVariable:varCreatedByEmail}",
                    "name": "{Common:InitiatorsDisplayName}",
                    "recipientId": "1",
                    "roleName": "MI Employee",
                    "routingOrder": "1"
                },
                {
                    "email": "{ItemProperty:E_x002d_Mail}",
                    "name": "{ItemProperty:Primary_x0020_Contact}",
                    "recipientId": "2",
                    "roleName": "Vendor",
                    "routingOrder": "2",
                    "tabs": {
                    "textTabs": [
                    {
                    "tabLabel": "VendorName"}]}
                },
                {
                    "email": "{WorkflowVariable:varContractApproverEmail}",
                    "name": "{WorkflowVariable:varContractApproverName}",
                    "recipientId": "3",
                    "roleName": "MI Approver",
                    "routingOrder": "3"
                }
                ]
            }
        }],
        "document": {
            "documentId": 4,
            "name": "CCare_Pledge.pdf"
        }
    }]
    }
    
    --MY_BOUNDARY
    Content-Type: application/pdf
    Content-Disposition: file; filename="{WorkflowVariable:varContractName}";     documentid="1"
    
    <document bytes removed>
    
    --MY_BOUNDARY--
    Content-Type: application/pdf
    Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}";     documentid="2"
    
    <document bytes removed>
    
    --MY_BOUNDARY--
    Content-Type: application/pdf
    Content-Disposition: file; filename="CCare_Pledge.pdf"; documentid="4"
    

    链接到base64- http://www.mihomes.com/corp/vit/Base64.txt

1 个答案:

答案 0 :(得分:0)

在查看您发布的请求时,我发现了一些事情:

首先,您错误地将指定 documentid = 2 的部分的边界分隔符指定为“ - MY_BOUNDARY -

--MY_BOUNDARY--
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}";     documentid="2"

通过在此边界字符串的末尾包含 - ,您指示多部分消息的结束,因此DocuSign很可能没有读取任何请求内容这个字符串。我建议将其更改为“ - MY_BOUNDARY”

其次,您为两个文档(documentid = 1和documentid = 2)多次指定文档字节 - 一次作为文档对象的一部分(使用 documentbase64 属性)在每个复合模板中,并再次在多部分请求的其他部分中。我建议从每个Composite Template对象的 document 对象中删除 documentbase64 属性 - 如果你在multipart的其他部分指定文档字节,则不需要它消息。

接下来,如果 CCare_Pledge.pdf 是您正在使用的模板中包含的第一个文档,那么您应该从该复合模板中删除文档属性(对象)对象:

"document": {
    "documentId": 4,
    "name": "CCare_Pledge.pdf"
}

并删除请求的最后部分:

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

这不是必需的,因为文档来自模板本身,因此您无需在请求中指定文档信息。

最后,确保您的请求以正确的边界终止符字符串结束:

--MY_BOUNDARY--

(这个other post的答案显示了关于边界分隔符的整体请求结构的一个很好的例子。)

一旦实施了这些建议的更改,您的请求结构应如下所示:

--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data

{
    "emailSubject": "Contract Package for {ItemProperty:Title}",
    "status" : "sent",
    "compositeTemplates": [
        {
            "inlineTemplates": [
                {
                    "sequence" : 2,
                    "recipients": {
                        ...
                    }
                }
            ],
            "document": {
                "documentId": 1,
                "name": "{WorkflowVariable:varContractName}"
            }
        },
        {
            "inlineTemplates": [
                {
                    "sequence" : 3,
                    "recipients": {
                        ...
                    }
                }
            ],
            "document": {
                "documentId": 2,
                "name": "{WorkflowVariable:varExhibitAName}"
            }
        },
        {
            "serverTemplates": [
                {
                    "sequence" : 6,
                    "templateId": "D7472F81-46F9-4BEB-9017-DFAD3C0BCE83"
                }
            ],
            "inlineTemplates": [
                {
                    "sequence" : 7,
                    "recipients": {
                        ...
                    }
                }
            ]
        }
    ]
}

--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varContractName}"; documentid="1"

<document bytes removed>

--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="{WorkflowVariable:varExhibitAName}"; documentid="2"

<document bytes removed>

--MY_BOUNDARY--