如何使用Docusign REST API将模板应用于文档 [英] How do I apply a template to a document using Docusign REST API

查看:117
本文介绍了如何使用Docusign REST API将模板应用于文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用docusign rest API,我想知道是否有人举了一个例子,说明如何在一个信封中添加文档和模板。我可以访问所需的模板ID,并且已使用复合模板创建了包含多个带有相应模板的文档的信封。我只使用模板ID来执行此操作。现在,我试图找出如何向复合模板添加文档。如果文档包含模板(如果有模板,我可以访问模板ID),则应将模板应用于该文档。

I'm currently working with the docusign rest API and I'm wondering if anyone has an example of how I can add documents and templates in one envelope. I have access to the template id's I need and I've used composite templates to create an envelope with multiple documents with corresponding templates. I'm doing this ONLY using the template id though. Now I'm trying to figure out how to add a document to the composite template. If the document contains a template(I have access to the template ids if it does have one) it should apply the template to that document.

我可以将模板应用于模板吗?通过其余的API文档?如果是这样,有人有示例吗?

Can I apply templates to a document through the rest API? If so, does anyone have an example?

推荐答案

下面是几个示例,这些示例显示了如何使用组合模板来组合模板中的信息以及通过API请求本身指定的信息。

Here are a couple of examples that show how Composite Templates can be utilized to combine information from Template(s) with information specified via the API request itself.

示例1:

以下示例请求创建一个信封,其中的模板用于定义信封的标签和收件人角色,但是文档和收件人信息由API请求本身提供。

The following example request creates an Envelope where the Template is used to define the tags and recipient roles for the Envelope, but the Document and Recipient information is provided by in the API request itself.

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

{
    "emailBlurb":"Test Email Body",
    "emailSubject": "Test Email Subject",
    "status" : "sent",
    "compositeTemplates": [
    {
        "serverTemplates": [
        {
            "sequence" : 1,
            "templateId": "TEMPLATE_ID"
        }],
        "inlineTemplates": [
        {
            "sequence" : 2,
            "recipients": {
                "signers" : [{
                    "email": "bettysemail@outlook.com",
                    "name": "Betty Adamson",
                    "recipientId": "1",
                    "roleName": "RoleOne"
                }]
            }
        }],
        "document": {
            "documentId": 1,
            "name": "test1.pdf"
        }
    }]
}

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

<document bytes removed>

--MY_BOUNDARY--

如上所示,提供文件( s)通过API请求本身要求您提交多部分请求-其中第一部分代表请求的完整JSON,而请求的每个后续部分代表单个内容JSON中引用的文档。如果您的JSON引用了多个文档,则您的请求将为每个文档包含一个额外的/单独的 部分

As shown above, to provide document(s) via the API request itself requires that you submit a multi-part request -- where the first part represents the complete JSON for the Request, and each subsequent Part of the Request represents the contents of a single document that's referenced in the JSON. If your JSON references multiple documents, your request would contain an additional/separate part for each document.

复合模板功能强大,可以为您提供极大的灵活性,可以将模板中的信息与运行时通过API请求本身提供的信息(文档,收件人)结合在一起。上面的示例非常简单(一个模板,一个文档,一个收件人),但是对于想要合并多个模板/文档/收件人的情况,可以轻松扩展。

Composite Templates are powerful in that they give you great flexibility in terms of combining information from Templates with information (documents, recipients) provided via the API request itself at runtime. The above example is very simple (one template, one document, one recipient) -- but it can easily be extended for cases where you want to combine multiple templates/documents/recipients.

(《 REST API指南》 p26-27上的示例请求显示了发送多部分请求时所需的基本格式: http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf 。)

(The example request on p26-27 of REST API Guide shows the basic format that's required when sending a multi-part request: http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf.)

示例2:

接下来,假设您要在信封中包含模板中定义的所有文档,但是您还希望在信封中包含两个其他文档(不是由模板定义)。以下示例请求创建一个包含2个文档的信封,这些文档是API请求的一部分(CustomerAgreement.pdf和Invoice.pdf),以及由第3个Composite Template结构中引用的Template定义的所有文档。一些一般性注意事项:

Next, let's assume that you want to include in an Envelope all of the documents that are defined in a Template, but you also want to include two additional documents (not defined by a Template) in the Envelope. The following example request creates an Envelope with 2 documents that are specified as part of the API request (CustomerAgreement.pdf and Invoice.pdf), and all documents that are defined by the Template that's referenced in the 3rd Composite Template structure. A couple of general notes:


  • 文档将按照在信封中指定的
    的顺序显示在信封中。 JSON请求。在此示例中,这意味着文档顺序为:1)CustomerAgreement.pdf(通过第一个复合模板结构中的API请求指定),2)Invoice.pdf(通过第二个复合模板结构中的API请求指定)和3 )在第三个复合模板结构中引用的模板指定的所有文档。

  • Documents will appear in the Envelope in the order that they are specified in the JSON request. In this example, that means document order is: 1) CustomerAgreement.pdf (specified via the API request in the first Composite Template structure), 2) Invoice.pdf (specified via the API request in the second Composite Template structure), and 3) all documents specified by the Template that's referenced in the third Composite Template structure.

尽管每个单独的复合模板结构都必须指定收件人信息-DocuSign将匹配/在形成信封的收件人集合时合并所有相同的收件人信息。在此示例中,生成的信封只有一个收件人:Abby Abbott。

Although each individual Composite Template structure must specify recipient info -- DocuSign will match/merge any identical recipient info when forming the recipient collection for the Envelope. In this example, the resulting Envelope has only one recipient: Abby Abbott.

因为我们通过API请求,该请求共分为三个部分:1)JSON,2)第一个文档的内容,3)第二个文档的内容。

Because we're specifying two documents via the API request, the request has a total of THREE parts: 1) JSON, 2) contents of first document, 3) contents of second document.

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"
        }
    },
    {
        "inlineTemplates": [
        {
            "sequence" : 2,
            "recipients": {
                "signers" : [{
                    "email": "abbysemail@outlook.com",
                    "name": "Abby Abbott",
                    "recipientId": "1"
                }]
            }
        }],
        "document": {
            "documentId": 2,
            "name": "Invoice",
            "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"

    <document bytes removed>

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

    <document bytes removed>

--MY_BOUNDARY--

这篇关于如何使用Docusign REST API将模板应用于文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆