自定义文档字段

时间:2015-01-24 06:31:57

标签: docusignapi

我正在使用dev帐户和demo.docusign.net网站来测试API。我想创建一个包含自定义数据字段的文档的模板。我创建了一个模板,在您将字段拖到文档的页面上,我创建了一个自定义字段。我称之为“姓氏”。我保存了自定义字段并保存了模板。现在我想创建一个新文档,用于通过API进行签名并填充该字段。使用演练作为指导,我能够从模板创建新的草稿信封。然后我想用数据填充自定义字段。但是,这是失败的。我收到以下错误:

{   “errorCode”:“INVALID_REQUEST_BODY”,   “message”:“请求正文丢失或格式不正确。” }“

以下是基于演练的代码。除了在设计时附加自定义字段外,我还想测试动态添加新的自定义字段并进行修改。因此,首先我发出POST请求以添加新字段并使用Recipients / Tabs API进行设置。然后我发出GET请求以获取收件人的选项卡,以便我可以捕获标签ID。然后我发出一个PUT请求来修改字段,这就是我收到错误消息的地方。但请求正文对我来说很好,它包含TagId唯一必需的字段。我假设唯一需要的其他字段是设置值的字段。相同的请求正文适用于POST请求。我只是复制了它并更改了字段。 POST工作正常,我可以通过在控制台中打开它来验证添加的字段。新的领域就在那里。只是修改它的PUT不起作用。

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Add New Tab
/////////////////////////////////////////////////////////////////////////////////////////////////                                                                                  
$curl = curl_init($baseUrl . "/envelopes/" . $envelopeId . "/recipients/1/tabs" );
$data = array (
  'textTabs' => 
  array (
    0 => 
    array (
      'documentId' => '1',
      'pageNumber' => '1',
      'tabLabel' => 'test tab',
      'value' => 'test',
    ),
  ),
);

$data_string = json_encode($data);  


curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )                                                                       
);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
    echo "error calling webservice, status is:" . $status;

    exit(-1);
}

$response = json_decode($json_response, true);
curl_close($curl);

//--- display results



/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Get recipient tab information
/////////////////////////////////////////////////////////////////////////////////////////////////                                                                                  
$curl = curl_init($baseUrl . "/envelopes/" . $envelopeId . "/recipients/1/tabs" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    "X-DocuSign-Authentication: $header" )                                                                       
);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
    echo "error calling webservice, status is:" . $status;

    exit(-1);
}

$response = json_decode($json_response, true);
curl_close($curl);

$lastNameTabID = $response['textTabs'][0]['tabId'];
$testTabID = $response['textTabs'][1]['tabId'];
//--- display results

/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - update tab value
/////////////////////////////////////////////////////////////////////////////////////////////////                                                                                  
$curl = curl_init($baseUrl . "/envelopes/" . $envelopeId . "/recipients/1/tabs" );
$data = array (
  'textTabs' => 
  array (
    0 => 
    array (
      'tabId' => $testTabID,
      'value' => 'Some Value',
    ),
  ),
);

$data_string = json_encode($data);  


curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string),
    "X-DocuSign-Authentication: $header" )                                                                       
);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
    echo "error calling webservice, status is:" . $status;

    exit(-1);
}

$response = json_decode($json_response, true);
curl_close($curl);

这是请求正文的输出

data_string ='{“textTabs”:[{“tabId”:“627883d0-542c-40c7-a58c-ce68d9e057e1”,“value”:“Some Value”}]}''

我很感激一些指导。

由于 乔

2 个答案:

答案 0 :(得分:3)

我认为这比我们想象的要容易。您应该能够在帖子中定义附加标签以创建信封。下面是我的json的一部分,用于定义模板角色和文本选项卡。第一个是在标有“公司”的模板中定义的字段。第二个是我正在添加的数据字段,并使用XY坐标放置在第3页上。您也可以使用锚文本放置它。

"templateRoles": [
{
  "tabs": {
    "textTabs": [
      {
        "tabLabel": "Company",
        "value": "Acme Inc"
      },
      {
        "tabLabel": "business",
        "value": "widgets",
        "pageNumber": "3",
        "documentId": "1",
        "yPosition": "300",
        "xPosition": "300",
        "locked": false
      }
    ]
  },
  "roleName": "Customer",
  "name": "Customer Bob",
  "email": "signerrob@outlook.com"
}

],

答案 1 :(得分:1)

好吧,所以我做了一点挖掘,并认为我有我们需要的东西。首先,要获取信封的收件人ID以及相关的标签ID,请使用以下GET:v2 / accounts /:accountId / envelopes /:envelopeId / recipients。这将为您提供编辑现有标签所需的内容。获得此处的信息后,您可以使用PUT v2 / accounts /:accountId / envelopes /:envelopeId / recipients /:recipientId / tabs来编辑您要编辑的标签。以下是我使用Postman发送的成功更新文本选项卡值的JSON请求示例。

{
  "textTabs": [
    {
      "tabId": "c75d32c4-8024-48c0-975a-acc232b20212",
      "value": "ABC Corp",
    }
  ]
}

要向该收件人添加标签,请使用与编辑相同的网址,但请使用POST。