I am using the docusign rest api. I am trying to create a template and then use embedded sending.
Here is my code:
Create a template:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$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 ) {
$status = 'notok';
}
$response = json_decode($json_response, true);
if( (isset($response['errorCode'])) && ($response['errorCode'] == 'USER_LACKS_PERMISSIONS')) {
echo $msg = 'This user lacks sufficient permissions';
$_SESSION['msg_frm_apd'] = $msg;
}
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
$template_name = "template_" . time();
$data = "{
\"emailBlurb\":\"String content\",
\"emailSubject\":\"String content\",
\"documents\": [{
\"documentId\": \"1\",
\"name\": \"document.pdf\"
}],
\"recipients\": {
\"signers\": [{
\"recipientId\": \"1\",
\"roleName\": \"Signer 1\"
}]
},
\"envelopeTemplateDefinition\": {
\"description\": \"Description\",
\"name\": \"$template_name\"
}
}";
$file_contents = file_get_contents("uploads/envelopes/" . $file_name);
$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"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\”document.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
$url = "https://demo.docusign.net/restapi/v2/accounts/376082/templates";
$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: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$response = json_decode($json_response, true);
$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);
Embedded Sending:
$templateId = $response['templateId']; // provide a valid templateId of a template in your account
$clientUserId = "1234";
$templateRoleName = "Signer 1";
$data = array("accountId" => $accountId,
"emailSubject" => "DocuSign API - Embedded Sending Example",
"templateId" => $templateId,
"templateRoles" => array(
array( "roleName" => $templateRoleName, "email" => $recipient_email, "name" => $recipient_name, "clientUserId" => $clientUserId )),
"status" => "created");
$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" ) docusign
);
$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 Sending View (aka the "tag-and-send" view)
/////////////////////////////////////////////////////////////////////////////////////////////////
/*$data = array("returnUrl" => "http://www.docusign.com/devcenter");*/
$returnUrl = $SITE_URL . "/docusign_return.php";
$data = array("returnUrl" => $returnUrl);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/sender" );
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);
$response = json_decode($json_response, true);
$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);
}
$url = urlencode($response["url"]);
When i click on the above url, i am getting a page where i can tag and send the document. There is an email address
field in this page which is automatically populated with the $recipient_email. But the problem is that the mail is not going to the recipient email address. Thanks.(also i am not getting any error messages).
There is no problem with your code and it is working perfectly as expected. I can tell that you are using DocuSign's sample code from their API Walkthroughs.
If you're saying everything is working ok and no errors, but that after navigating to the embedded sending URL and sending the document for signature the recipient is not receiving the email I would check for things like security software, spam/junk mail filters, firewalls, etc on your side. The DocuSign service is so widely used that if the emails weren't going out in signature requests there would be a big stink about it pretty quickly, and on top of that I just did a test and my emails are going out just fine.
So as mentioned, if you're sure the email address is correct and you are hitting the SEND button through the UI, I'd check security software, spam/junk mail filters, firewalls, and anything else that might stop the email from arriving on your side.
Another suggestion for troubleshooting issues with email delivery: use DocuSign Connect. If your account is configured properly, you could enable Connect and use the Connect logs to detect if the recipient email is undeliverable (i.e., if DocuSign's receiving a 'bounce-back' when sending to that address).
Create a Custom Connect Configuration in DocuSign, as described in this guide: http://www.docusign.com/sites/default/files/DocuSign_Connect_Service_Guide.pdf.
In the Connect Configuration that you create, you can specify any URL as the URL to publish to -- all you're trying to do for this test is to make Connect send the notification for the "Recipient Sent" event and "Recipient Delivery Failed" event (and create Log entries for the notifications it sends) -- it doesn't matter that the endpoint you specify won't be equipped to receive/process the Connect message.
In the Connect Configuration that you create, be sure to select the options I've highlighted here (as previously stated, you can use any URL -- I just happened to have chosen google.com):
Once you've created and saved the Connect Configuration as described above, go through the process you describe in your question to create/send the Envelope.
Once you've sent the Envelope, login to the DocuSign web console (as Administrator), and view the Connect log entries. (i.e., navigate to Preferences >> Connect >> Logs
You should see log entries listed for each "Recipient Sent" and/or "Recipient Delivery Failed" event that's occurred since the time that you created/enabled the Connect Configuration.
Examining the contents of the log entries should allow you to determine if DocuSign is successfully sending the Recipient email(s), and also whether the Recipient email(s) are bouncing back as undeliverable.
If the log entries indicate that DocuSign is sending the Recipient email(s) and do NOT indicate any bounce-backs, then it's likely an issue with the Email client that's preventing the recipient from receiving the email(s) (as Ergin suggested in his answer).
Related
I am having a problem getting the below code to work in my developer account. I keep getting the following error:
"ERROR calling webservice, status is:400 error text is --> { "errorCode": "ENVELOPE_IS_INCOMPLETE", "message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line." }"
Anyone have an idea why this error is occuring? The "test.pdf" is located in the same directory as the docusign.php file that is the below code:
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Establish Credentials & Variables
/////////////////////////////////////////////////////////////////////////////////////////////////
// Input your info here:
$name = "John P. Doe"; //The user from Docusign (will show on the email as the sender of the contract)
$email = " MY EMAIL ACCOUT USED FOR DOCUSIGN ";
$password = " MY PASSWORD FOR DOCUSIGN "; // The password for the above user
$integratorKey = " MY API KEY FOR DEMO ";
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - 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"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "ERROR:<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 "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
echo "Document is being prepared. Please stand by.<br>Do not navigate away from this page until sending is confirmed.<br><br>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4 - Create an envelope using composite templates
/////////////////////////////////////////////////////////////////////////////////////////////////
$data_string =
"
{
\"status\":\"sent\",
\"emailSubject\":\"Test transforming pdf forms and assigning them to each user\",
\"emailBlurb\":\"Test transforming pdf forms and assigning them to each user\",
\"compositeTemplates\":[
{
\"inlineTemplates\":[
{
\"sequence\": \"1\",
\"recipients\":{
\"signers\":[
{
\"email\":\"test1#test.com\",
\"name\":\"Signer One\",
\"recipientId\":\"1\",
\"routingOrder\":\"1\",
\"tabs\":{
\"textTabs\":[
{
\"tabLabel\":\"PrimarySigner\",
\"value\":\"Signer One\"
}
]
}
},
{
\"email\":\"test2#test.com\",
\"name\":\"Signer Two\",
\"recipientId\":\"2\",
\"routingOrder\":\"2\",
\"tabs\":{
\"textTabs\":[
{
\"tabLabel\":\"SecondarySigner\",
\"value\":\"Secondary One\"
}
]
}
}
]
}
}
],
\"document\": {
\"documentId\": \"1\",
\"name\": \"test.pdf\",
\"transformPdfFields\": \"true\"
}
}
]
}
";
$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"];
// --- display results
echo "Document is sent!<br> Envelope: " . $envelopeId . "\n\n";
From what I can tell, the actual PDF Bytes of test.pdf are not being sent as part of this API request - therefore the error message is calling out the fact that you are referencing a document which is missing. Take a look at the PHP recipe examples for how you can read the PDF bytes in from a file and include it in your API request:
https://www.docusign.com/developer-center/recipes/request-a-signature-via-email
Specifically, this line and variable: $file_contents = file_get_contents($documentFileName);
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.
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.
i get this error calling webservice, status is:401 when i made a new account a member account (non developer account and try to integrate it in a form that i have..i based the code from the api walkthroughs in docusign itself
<?php
if(($_POST['submit']))
{
// Input your info here:
$integratorKey = 'XXXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX';
$email = 'XXXXXXXXXX';
$email1 = 'XXXXXXXXX';
$email2 = 'XXXXXXXX';
$password = 'XXXXXXXX';
$name = 'XXX';
$name2 = 'XXXXXX';
// 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"));
$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
/////////////////////////////////////////////////////////////////////////////////////////// //////
// STEP 2 - Create an envelope with one recipient, one tab, one document and send!
/////////////////////////////////////////////////////////////////////////////////////////// //////
$data = "{
\"emailBlurb\":\"This comes from Dateguard\",
\"emailSubject\":\"DocuSign API - Please Sign This Contract for Dateguard...\",
\"documents\":[
{
\"documentId\":\"1\",
\"name\":\"contract.pdf\"
}
],
\"recipients\":{
\"signers\":[
{
\"email\":\"$email1\",
\"name\":\"$name\",
\"recipientId\":\"1\",
\"tabs\":{
\"signHereTabs\":[
{
\"xPosition\":\"80\",
\"yPosition\":\"550\",
\"documentId\":\"1\",
\"pageNumber\":\"1\"
}
]
}
},
{
\"email\":\"$email2\",
\"name\":\"$name2\",
\"recipientId\":\"2\",
\"tabs\":{
\"signHereTabs\":[
{
\"xPosition\":\"400\",
\"yPosition\":\"550\",
\"documentId\":\"1\",
\"pageNumber\":\"1\"
}
]
}
}
]
},
\"status\":\"sent\"
}";
$file_contents = file_get_contents("contract.pdf");
$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"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"contract.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
$home_url = 'thanks.php';
header('Location: ' . $home_url);
}
?>
now the problem is when i use my developer account in docusign as credentials for the api it works but when i create a member account it does not( the free trial )..is it supposed to work that way?am i missing something? if it is then how am i supposed to use the api to work so that a member use their own account and use their own credentials and be able to use it in docusign api and not my own developer account because of the "test" indication. thanks in advance.
401 Authorization Required
If the code is good with developer account, then the reason should be the account privilege.
The API is not enabled on DocuSign free-trial accounts - it's enabled on free developer sandbox accounts (which do NOT expire after 30 days). The only way to create those accounts are through the DocuSign Developer Center .
Of course, if you have a live integration, meaning you passed Certification with DocuSign, then you might have a production account which has the api enabled, but while you are developing and testing you can only do so with developer accounts and not the free trials.
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.