将Docusign模板阵列添加到REST标头中

时间:2013-10-08 21:43:10

标签: php codeigniter rest docusignapi

所以我又回来了。我的问题是: 我在Codeigniter视图中的复选框中有一系列Docusign模板:

<?php
    echo form_open('create_envelope');
    foreach ($response["envelopeTemplates"] as $envelopeTemplate) { ?>
        <li><?php echo form_checkbox('templatearray[]', $envelopeTemplate["templateId"], FALSE), $envelopeTemplate["name"]; ?></li>
<?php } ?>

我要做的是将模板添加到我们的REST标头请求中:

$data = array(
    "accountId" => $accountId,
    "emailSubject" => "Hello World!",
    "emailBlurb" => "This comes from PHP",
    "templateId" => "ID from template array here",
    "templateRoles" => array(
        array(
            "tabs" => array(
            "textTabs" => array (
                array (
                    "tabLabel" => "lic_num", 
                    "value" => "$license_number"
                ),
                array (
                    "tabLabel" => "ubi_num",
                    "value" => "$ubi_number"
                ),
                array (
                    "tabLabel" => "tra_nam",
                    "value" => "$trade_name"
                )
             )
          ),
          "email" => "$applicant_email",
          "name" => "$applicant_name",
          "roleName" => "Applicant"
          ) 
     ),
    "status" => "sent"
);

这可能吗?

编辑:所以我让它使用循环来获取请求中的数据,但我遇到了一个有趣的问题。如果我在信封中放置一个或两个模板,它会发送正常。如果我放入两个以上,它会复制模板。这是我复杂循环的代码:

$compTempArray = array();
$applicant_name = $this->input->post("applicant_name");
$applicant_email = $this->input->post("applicant_email");
$license_number = $this->input->post("license_number");
$ubi_number = $this->input->post("ubi_number");
$trade_name = $this->input->post("trade_name");
foreach($hello as $key => $value) {
    if(sizeof($hello) > 1) {
        for($i = 1; $i < sizeof($hello); $i++) {
            $compTempArray[] = array("serverTemplates" => array(
                array(
                    "sequence" => $i,
                    "templateId" => $value
                )
            ),
            "inlineTemplates" => array(
                array(
                    "sequence" => $i,
                    "recipients" => array(
                        "signers" => array(
                            array(
                                "tabs" => array(
                                            "textTabs" => array (
                                                            array ("tabLabel" => "lic_num", "value" => $license_number),
                                                            array ("tabLabel" => "ubi_num", "value" => $ubi_number),
                                                            array ("tabLabel" => "tra_nam", "value" => $trade_name)
                                            )
                                ),
                                "email" => "*********@*****.com",
                                "name" => $applicant_name,
                                "recipientId" => "1",
                                "roleName" => "Applicant"
                            ),
                        )
                    )
                )
            ));

        }
        $data = array("accountId" => $accountId,
                      "emailSubject" => "Hello World!",
                      "emailBlurb" => "This comes from PHP",
                      "compositeTemplates" => $compTempArray,
                      "status" => "sent");
        } else {
            $data = array("accountId" => $accountId,
                      "emailSubject" => "Hello World!",
                      "emailBlurb" => "This comes from PHP",
                      "templateId" => "$value",
                      "templateRoles" => array(
                                            array(
                                                "tabs" => array(
                                                            "textTabs" => array (
                                                                            array ("tabLabel" => "lic_num", "value" => $license_number),
                                                                            array ("tabLabel" => "ubi_num", "value" => $ubi_number),
                                                                            array ("tabLabel" => "tra_nam", "value" => $trade_name)
                                                            )
                                                ),
                                                "email" => "*********@*****.com",
                                                "name" => $applicant_name,
                                                "roleName" => "Applicant"

                                            )   
                                         ),
                    "status" => "sent"); 
        }
    }

知道为什么会这样做吗?

新编辑:这个奇怪的更新:一到两个 - 每个模板的一个副本,三个 - 它使每个模板的数量增加一倍,四个 - 它使数量增加三倍,五个 - 它增加四倍量。

最新编辑:事实证明,这是我用来尝试增加序列的for循环。我摆脱了循环并将序列硬编码为1.修复了它。

1 个答案:

答案 0 :(得分:2)

要将多个模板应用于单个信封,您需要使用compositeTemplates结构。

compositeTemplates可以很快变得复杂,但它们确实为您的信封提供了极大的灵活性和功能。 API documentation是阅读compositeTemplates的最佳位置,但如前所述,April 2012 Templates Webinar也是一个很好的资源。第三个示例提供了compositeTemplates的基本用法,它向您展示了如何将两个服务器模板组合到一个单独的信封中。您可以将其用作JSON的基础。

要将2个服务器模板应用于单个信封,它将使用以下JSON:

{
  "emailSubject": "DocuSign Templates Webinar - Example 3",
  "emailBlurb": "Example #3 - Composite Templates",
  "status": "sent",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "1",
          "templateId": "55A80182-2E9F-435D-9B16-FD1E1C0F9D74"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "1",
          "recipients": {
            "signers": [
              {
                "email": "firstrecipient@gmail.com",
                "name": "John Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    },
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "2",
          "recipients": {
            "signers": [
              {
                "email": "secondrecipient@gmail.com",
                "name": "Jane Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    }
  ]
}

请注意,每个模板的sequence值确定模板应用到信封的顺序。换句话说,序列值决定了文档顺序,但由于模板可能具有匹配/冲突的信息(例如,就模板角色而言),序列值也可能影响信封的最终结果。