I'm using the dev account and the demo.docusign.net site to test out the API. I want to create a template with a document that has custom data fields. I created a template and on the page where you drag fields on to the document, I created a custom field. I called it "Last Name". I saved the custom field and saved the template. Now I want to create a new document for signing through the API and populate that field. Using the Walkthroughs as a guide, I was able to create a new draft envelope from a template. I then wanted to populate the custom field with data. However, this is failing. I'm getting the following error:
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted." }'
Below is my code based off the Walkthroughs. In addition to having a custom field attached at design time, I wanted to test dynamically adding a new custom field and modifying it as well. So, first I make a POST request to add a new field and set it using the Recipients/Tabs API. Then I make a GET request to get the Tabs for the recipient so I can capture the Tag ID. Then I make a PUT request to modify the field and that's where I get the error message. But the request body looks fine to me and it contains the only required field for TagId. I assume the only other needed field is one to set the value. The same request body works fine for the POST request. I just copied it and changed the fields. The POST works fine and I can validate the added field by opening it in the Console. The new field is there. It's just the PUT to modify that isn't working.
/////////////////////////////////////////////////////////////////////////////////////////////////
// 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);
And here is the output of the Request Body
data_string= '{"textTabs":[{"tabId":"627883d0-542c-40c7-a58c-ce68d9e057e1","value":"Some Value"}]}'
I appreciate some guidance.
Thanks Joe