Docusign REST API Getting recipient URL for document envelope - php

I have a web app that takes a user through a series of forms and then generates a pdf with their answers. I want to add a Docusign signature to the end of the pdf form, so that after finishing the online form they are asked to sign it in an iframe.
I started with this doc - https://www.docusign.com/developer-center/recipes/signing-from-your-app and then took step 2 from this doc to create my envelope with a document - https://www.docusign.com/developer-center/recipes/request-a-signature-via-email
My code created the Envelope ID fine, but when I try to get the URL using /envelopes/$envelopeId/views/recipient I get the status 400 error:
{ "errorCode": "ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE", "message": "This account is not authorized to access the requested envelope." }
Here is my full code below:
<?php
$docusign_username = "my#username.com";
$docusign_password = "mypassword";
$docusign_integrator_key = "my-integrator-key";
$applicant_email = "johnsmith#emailaddress.com";
$applicant_name = "John Smith";
$applicant_unique_id = "123";
$application_unique_id = "31587";
$application_form_pdf = "31587.pdf";
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $docusign_username . "</Username><Password>" . $docusign_password . "</Password><IntegratorKey>" . $docusign_integrator_key . "</IntegratorKey></DocuSignCredentials>";
//////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
//////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
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);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
//////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with document
//////////////////////////////////////////////////////////////////////////////////////
$data =
array (
"emailSubject" => "DocuSign API - Please sign " . $application_form_pdf,
"documents" => array(
array("documentId" => $application_unique_id, "name" => $application_form_pdf)
),
"recipients" => array(
"signers" => array(
array(
"email" => $applicant_email,
"name" => $applicant_name,
"clientUserId" => $applicant_unique_id,
"recipientId" => $applicant_unique_id,
"tabs" => array(
"signHereTabs" => array(
array(
"xPosition" => "100",
"yPosition" => "100",
"documentId" => $application_unique_id,
"pageNumber" => "1"
)
)
)
)
)
)
, "status" => "sent"
// , "status" => "created"
);
$data_string = json_encode($data);
$file_contents = file_get_contents($application_form_pdf);
// Create a multi-part request. First the form data, then the file content
$requestBody =
"\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"$application_form_pdf\"; documentid=".$application_unique_id." \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// Send to the /envelopes end point, which is relative to the baseUrl received above.
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl); // Do it!
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "Error calling DocuSign, status is:" . $status . "\nerror text: ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Envelope created! Envelope ID: " . $envelopeId . "\n";
//////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Signing View
//////////////////////////////////////////////////////////////////////////////////////
$data = array(
"returnUrl" => "https://www.docusign.com/devcenter"
, "authenticationMethod" => "None"
, "authenticationInstant" => "None"
, "userId" => $applicant_unique_id
, "clientUserId" => $applicant_unique_id
// , "email" => $applicant_email
// , "userName" => $applicant_name
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl."/envelopes/$envelopeId/views/recipient" );
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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$url = $response["url"];
//--- display results
echo "Embedded URL is: \n\n" . $url . "\n\nNavigate to this URL to start the embedded signing view of the envelope\n";
?>
Any ideas would be gratefully received, thanks!

When obtaining the recipient view (the signing view), try identifying the signer by just specifying the
"email" => $email, # signer's email
"userName" => $recipientName,
"clientUserId" => $clientUserId
as shown in the embedded signing recipe.
Don't set the userId

Related

Submit form and prepopulate custom fields in DocuSign Envelope

For some reason I can't get my code to show the custom fields I am wanting to add in the left pane(e.g. First Name, Last Name, etc.). On submit my form should go to the envelope and prepopulate my custom fields. I've searched the DocuSign docs and also different threads on here. Any help is much appreciated. Thank you.
<?php
if(!empty($_POST)){
// Input your info:
$email = "foor#bar.com"; // your account email
$password = "password"; // your account password
$integratorKey = "wouldnt-you-like-to-know"; // your account integrator key, found on (Preferences -> API page)
$templateId = "66b7706e-936b-4438-bd5e-bd68ce47dffb"; // provide a valid templateId of a template in your account
$templateRoleName = "Test"; // use same role name that exists on the template in the console
$recipientName = 'blah bleh'; // provide a recipient (signer) name
$recipientEmail = 'yee#haw.com';
// the recipient name and email. Whatever you set the clientUserId to you must use the same
// value when requesting the signing URL
// construct the authentication header:
$color = $_POST['color'];
$number = $_POST['number'];
$animal = $_POST['animal'];
$header =
"<DocuSignCredentials>
<Username>" .
$email .
"</Username>
<Password>" .
$password .
"</Password>
<IntegratorKey>" .
$integratorKey .
"</IntegratorKey>
</DocuSignCredentials>";
// STEP 1 - Login (retrieves baseUrl and accountId)
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
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 "<br>";
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n" . "<br>";
// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
$data = array(
"accountId" => $accountId,
"emailSubject" => "DocuSign API - Embedded Signing Example",
"emailBlurb" => "This is a test.",
"compositeTemplates" => array(
"serverTemplates" => array(
"sequence" => "1",
"templateId" => $templateId
),
"inlineTemplates" => array(
"sequence" => "2",
"recipients" => array(
"signers" => array(
"roleName" => "Signer1",
"recipientId" => "1",
"name" => "John Doe",
"email" => "johndoe#test.com",
"clientUserId" => "1234",
"tabs" => array(
"textTabs" => array(
"tabLabel" => "address",
"value" => "123 Main Street"
)
)
)
)
)
),
"status" => "sent"
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 . "\nerror text is --> <br>";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);
//--- display results
echo "<br>Envelope created! Envelope ID: " . $envelopeId . "\n";
// STEP 3 - Get the Embedded Signing View
$data = array(
"returnUrl" => "http://www.docusign.com/devcenter",
"authenticationMethod" => "Email",
"clientUserId" => "1234",
"userName" => "John Doe",
"email" => "johnDoe#test.com"
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$url = $response["url"];
//--- display results
echo "\n\nNavigate to this URL to start the embedded signing view of the envelope\n" . "<br>Embedded URL is: \n\n" . "<a href='$url'>HERE!</a>";
}
?>
<form action="" method="POST">
<label for="color">color:</label>
<input type="text" name="color">
<br>
<label for="number">number:</label>
<input type="text" name="number">
<br>
<label for="animal">animal:</label>
<input type="text" name="animal">
<br>
<button type="submit">Submit</button>
</form>
To create an Envelope using a Template and pre-populate field(s) within that Envelope's documents requires that you use the Composite Templates structure in the API request. (See the "Composite Templates" section on this page for info about Composite Templates.)
I'm not familiar with the DocuSign PHP SDK, but will explain the request syntax in JSON, and I imagine you can figure out the corresponding PHP syntax to generate the requests as shown.
The following example request (JSON) creates an Envelope that uses the specified Template with a single recipient (role name = Signer1), and pre-populates the address field with value "123 Main Street" for that recipient (embedded signer). (Although this example pre-fills just a single field for Signer1 -- you could obviously pre-fill additional fields by simply including them in the tabs object of the request along with address.)
POST https://{{env}}.docusign.net/restapi//v2/accounts/{{accountId}}/envelopes
{
"emailSubject": "Test Pre-fill Tabs",
"emailBlurb": "This is a test.",
"compositeTemplates": [{
"serverTemplates": [{
"sequence": "1",
"templateId": "CD0E6D53-3447-4A9E-BBAF-0EB2C78E8310"
}],
"inlineTemplates":[{
"sequence": "2",
"recipients": {
"signers": [
{
"roleName": "Signer1",
"recipientId": "1",
"name": "John Doe",
"email": "johndoe#test.com",
"clientUserId": "1234",
"tabs": {
"textTabs": [
{
"tabLabel": "address",
"value": "123 Main Street"
}
]
}
}
]
}
}]
}],
"status": "sent"
}
Once you've created the Envelope (using the above request), you'll execute a "POST Recipient View" request to get the signing URL for Signer1:
POST https://{{env}}.docusign.net/restapi//v2/accounts/{{accountId}}/envelopes/{{envelopeId/views/recipient
{
"clientUserId": "1234",
"userName": "John Doe",
"email": "johndoe#test.com",
"returnUrl": "https://www.google.com",
"authenticationMethod": "Email"
}
(Notice that you don't specify tabs in this request.)
UPDATE #1
Starting with the code you added to your original post, I've been able to modify it such that it's now successfully creating an Envelope (using a Template), with a single embedded recipient (Signer1) and pre-populating the address text field for that signer. Here is the code -- please note that you'll need to specify values for all variables at the top of this code example.
<?php
// Set values for variables
//-----------
$email = "YOUR_DOCUSIGN_LOGIN_EMAIL"; // your account email
$password = "YOUR_DOCUSIGN_LOGIN_PASSWORD"; // your account password
$integratorKey = "YOUR_DOCUSIGN_INTEGRATOR_KEY"; // your account integrator key, found on (Preferences -> API page)
$templateId = "TEMPLATE_ID"; // provide a valid templateId of a template in your account
$templateRoleName = "TEMPLATE_RECIPIENT_ROLE_NAME"; // use same role name that exists on the template in the console
$recipientName = "SIGNER_NAME"; // provide a recipient (signer) name
$recipientEmail = "SIGNER_EMAIL_ADDRESS"; // provide a recipient (signer) email address
$recipientId = "1"; // set recipient id (can be any integer value)
$clientUserId = "1234"; // set clientUserId (can be any integer value) -- this is what makes the recipient an "embedded recipient (signer)"
$header =
"<DocuSignCredentials>
<Username>" .
$email .
"</Username>
<Password>" .
$password .
"</Password>
<IntegratorKey>" .
$integratorKey .
"</IntegratorKey></DocuSignCredentials>";
// STEP 1 - Login (retrieves baseUrl and accountId)
//-----------
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
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 "\n";
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n\n";
// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
//-----------
// tabs
$textTabs = array();
$textTabs[] = array('tabLabel' => "address", 'value' => "123 Main Street");
$tabs = array('textTabs' => $textTabs);
#echo ("tabs:\n" . json_encode($tabs) . "\n\n");
// recipients
$signers = array();
$signers[] = array('roleName' => $templateRoleName, 'recipientId' => $recipientId, 'name' => $recipientName, 'email' => $recipientEmail, 'clientUserId' => $clientUserId, 'tabs' => $tabs);
$recipients = array('signers' => $signers);
#echo ("recipients:\n" . json_encode($recipients) . "\n\n");
// serverTemplates
$serverTemplates = array();
$serverTemplates[] = array('sequence' => "1", 'templateId' => $templateId);
#echo ("serverTemplates:\n " . json_encode($serverTemplates) . "\n\n");
// inlineTemplates
$inlineTemplates = array();
$inlineTemplates[] = array('sequence' => "2", 'recipients' => $recipients);
#echo ("inlineTemplates:\n" . json_encode($inlineTemplates) . "\n\n");
// compositeTemplates
$compositeTemplates = array();
$compositeTemplates[] = array('serverTemplates' => $serverTemplates ,'inlineTemplates' => $inlineTemplates);
#echo ("compositeTemplates:\n" . json_encode($compositeTemplates) . "\n\n");
// request body
$data = array('emailSubject' => "DocuSign Test - Embedded Signing", 'emailBlurb' => "Please sign. Thanks!", 'status' => 'sent', 'compositeTemplates' => $compositeTemplates);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 . "\nerror text is --> \n";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);
//--- display results
echo "\nEnvelope created! Envelope ID: " . $envelopeId . "\n";
// STEP 3 - Get the Embedded Signing View
//-----------
$data = array(
"returnUrl" => "http://www.docusign.com/devcenter",
"authenticationMethod" => "Email",
"clientUserId" => $clientUserId,
"userName" => $recipientName,
"email" => $recipientEmail
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$url = $response["url"];
//--- display results
echo "\n\nNavigate to this URL to start the embedded signing view of the envelope:\n\n" . $url . "\n\n";
?>
Disclaimer: although this code is functional and achieves the objective, this is my first foray into working with PHP, so there's likely a better (more efficient) way to write this code. I welcome feedback if any PHP experts are so inclined.

Embedded document for Signing -Docu sign REST API

I`m using REST api for embedding signing.I want to embedded a document for signing in the website for each user who logged into my website. For this I have created a Template and add some tags and set them as required. While creating the template in the 'Recipients and Routing' section I have provided only one signer email and name. For generating the url for embedded signing I have used the following code
<?php
// Input your info:
$email = "***"; // your account email
$password = "***"; // your account password
$integratorKey = "***"; // your account integrator key, found on (Preferences -> API page)
$recipientName = "***"; // provide a recipient (signer) name
$templateId = "***"; // provide a valid templateId of a template in your account
$templateRoleName = "***"; // use same role name that exists on the template in the console
$clientUserId = "***"; // to add an embedded recipient you must set their clientUserId property in addition to
// the recipient name and email. Whatever you set the clientUserId to you must use the same
// value when requesting the signing URL
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
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);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("accountId" => $accountId,
"emailSubject" => "DocuSign API - Embedded Signing Example",
"templateId" => $templateId,
"templateRoles" => array(
array( "roleName" => $templateRoleName, "email" => $email, "name" => $recipientName, "clientUserId" => $clientUserId )),
"status" => "sent");
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes" );
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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);
//--- display results
echo "Envelope created! Envelope ID: " . $envelopeId . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Singing View
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("returnUrl" => "http://www.docusign.com/devcenter",
"authenticationMethod" => "None", "email" => $email,
"userName" => $recipientName, "clientUserId" => $clientUserId
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$url = $response["url"];
//--- display results
echo "Embedded URL is: \n\n" . $url . "\n\nNavigate to this URL to start the embedded signing view of the envelope\n";
?>
And its successfully generate the link. But the problem is that I can`t see the tags I have set in the template, and there is a list of fields in the left side .Is there any additional setting to display the tags in the documents itself for all the users who logged to access the document for signing.
As a follow up here, looks like the issue was due to not matching your recipient to the roleName on the template. For the benefit of the community, whenever you are creating an envelope / requesting a signature from a Template, you need to make sure you specify the same exact roleName in your API request as you gave the template role in the DocuSign Console.

Webservice error 400 while using Docusign API in php

Hello friends I am using an HTTP server to access Doucsign. And I am getting server problem
That is server error 400 and errorCode.
INVALID_EMAIL_ADDRESS_FOR_RECIPIENT", "message": "The email address
for the recipient is invalid. The recipient Id follows.
My code is
<?php
// Input your info here:
$email = "****"; // your account email
$password = "*******"; // your account password
$integratorKey = "*********"; // your account integrator key, found on (Preferences -> API page)
$recipientName = "usa usa"; // provide a recipient (signer) name
$documentName = "proposal.pdf"; // copy document with same name into this directory!
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$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);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with one recipient, one tab, and one document and send
/////////////////////////////////////////////////////////////////////////////////////////////////
// the following request body will place 1 signature tab on the document you supply, located
// 100 pixels to the right and 100 pixels down from the top left of the document
$data = array (
"emailSubject" => "DocuSign API - Signature Request on Document",
"documents" => array( array( "documentId" => "1", "name" => $documentName)),
"recipients" => array( "signers" => array(
array( "email" => $email,
"name" => $recipientName,
"recipientId" => "1",
"tabs" => array(
"signHereTabs" => array(
array( "xPosition" => "100",
"yPosition" => "100",
"documentId" => "1",
"pageNumber" => "1" )
))
))
),
"status" => "sent"
);
$data_string = json_encode($data);
$file_contents = file_get_contents($documentName);
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"$documentName\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo $status;
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "\n\n";
Can anyone help me? Thanks in advance.

docusign api create new account

i have created a master account manually on docusign and now i want to create new users using this account. This is my code:
$integratorKey = 'XXXX-XXXXX-XXXX-XXXX-XXXX-XXXXXXXX';
$email = 'my-email';
$password = 'XXXX';
$name = 'User';
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$data = '{
"newUsers":[{
"activationAccessCode":"",
"email":"my-email#gmail.com",
"enableConnectForUser":"",
"firstName":"",
"forgottenPasswordInfo":{
"forgottenPasswordAnswer1":"",
"forgottenPasswordAnswer2":"",
"forgottenPasswordAnswer3":"",
"forgottenPasswordAnswer4":"",
"forgottenPasswordQuestion1":"",
"forgottenPasswordQuestion2":"",
"forgottenPasswordQuestion3":"",
"forgottenPasswordQuestion4":""
},
"groupList":{
"groupId":"",
"groupId":""
},
"lastName":"",
"middleName":"",
"password":"",
"sendActivationOnInvalidLogin":"",
"suffixName":"",
"title":"",
"userName":"username",
"userSettings":[{
"name":"",
"value":""
}]
}]
}';
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data\r\n"
."--myboundary--\r\n"
."\r\n";
$url = "https://demo.docusign.net/restapi/v2/accounts";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($requestBody),
"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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
var_dump($response);
The error that i am getting is this : { "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Input string was not in a correct format." }. Could anyone tell me what is the issue?
Developer had an issue with the json format. There were unwanted values that got removed and it's now working (Based on comments above). Making sure this is marked as answered.

Integration of docusignapi via PHP CURL issue : error calling webservice, status is:0

Good Day i'm new to this docusignapi integration via PHP curl and i want to try this integration. I've copy the code below from http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromDocument and hoping i can easily test and understand how the integration works. But unfortunately an error always occur "error calling webservice, status is:0". I've tried other work around like changing the header format from XML to JSON but the error still shows up. Please help.
// Input your info here:
$integratorKey = 'XXXX-9999X9XX-X999-9999-99X9-9X9999X9XX9X';
$email = 'name#domain.com';
$password = 'samplepassword';
$name = 'Sender Full Name';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
print_r(curl_getinfo($curl));
echo "<br/>";
$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);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with one recipient, one tab, and one document and send
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array (
"emailBlurb" => "This comes from PHP",
"emailSubject" => "API Signature Request",
"documents" => array(array( "documentId" => "1", "name" => "testDS.pdf")),
"recipients" => array( "signers" => array(
array( "email" => $email,
"name" => $name,
"recipientId" => "1",
"tabs" => array(
"signHereTabs" => array(
array(
"xPosition" => "100",
"yPosition" => "100",
"documentId" => "1",
"pageNumber" => "1"
)
)
)
)
)
),
"status" => "sent");
$data_string = json_encode($data);
$file_contents = file_get_contents("testDS.pdf");
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\ā€testDS.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"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 . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "\n\n";
Is there any possibilities that my integratorkey is not valid? if yes, is there any way for me to check if my integrator key is valid or not?
In creating my integratorkey i just followed the procedure in this link http://www.docusign.com/developer-center/quick-start/first-api-call
I can't see anything wrong with the code right away. Whenever no status is returned at all it's usually one of three things that may be causing this:
Security software stopping your request from going through.
A Firewall stopping your request from going through.
Port 443 being closed for some other reason (other than 2 or 3).
Do you have any logs you can check to see if your requests are being intercepted, either at the software level or hardware level (if you have a hardware firewall)? I'd start by checking things like that.

Categories