MidhunKrishna
MidhunKrishna

Reputation: 621

how to get the document url to add custom fields using docusign api

I am trying to integrate docusign embedded signing into my hybrid app and i am loading the signing url in an iframe in my app, but is there any way to add some more custom fields on the fly using that signing url and make it in an unlocked state so that i can drag them where i want, and then make those fields locked at the time of sending to the sender for signing, also how to get the url of that document after he has signed it so that i can view it later.

Since i am a newbie in this please help me.

This is my code to get the signing url

<?php
$min=100;
$max=300;
$random = rand($min,$max);
$recipientId=rand();
require_once('vendor/autoload.php');
//require_once('./docusign-php-client/autoload.php');
// DocuSign account credentials & Integrator Key
$username = "[email protected]";
$password = "test1234";
$integrator_key = "[integrator-key]";
$host = "https://demo.docusign.net/restapi";
// create a new DocuSign configuration and assign host and header(s)
$config = new DocuSign\eSign\Configuration();
$config->setHost($host);
$config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");
/////////////////////////////////////////////////////////////////////////
// STEP 1:  Login() API
/////////////////////////////////////////////////////////////////////////
// instantiate a new docusign api client
$apiClient = new DocuSign\eSign\ApiClient($config);
// we will first make the Login() call which exists in the AuthenticationApi...
$authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
// optional login parameters
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
// call the login() API
$loginInformation = $authenticationApi->login($options);
// parse the login results
if(isset($loginInformation) && count($loginInformation) > 0)
{
    // note: defaulting to first account found, user might be a 
    // member of multiple accounts
    $loginAccount = $loginInformation->getLoginAccounts()[0];
    if(isset($loginInformation))
    {
        $accountId = $loginAccount->getAccountId();
        if(!empty($accountId))
        {
            echo "<b>Account ID</b> = $accountId</br>";
        }
    }
}
/////////////////////////////////////////////////////////////////////////
// STEP 2:  Create & Send Envelope with Embedded Recipient
/////////////////////////////////////////////////////////////////////////
// set recipient information
$recipientName = "username";
$recipientEmail = "[email protected]";
// configure the document we want signed
$documentFileName = "/abcd_test_01.pdf";
$documentName = "abcd_test.pdf";
// instantiate a new envelopeApi object
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
// Add a document to the envelope
$document = new DocuSign\eSign\Model\Document();
$document->setDocumentBase64(base64_encode(file_get_contents(__DIR__ . $documentFileName)));
$document->setName($documentName);
$document->setDocumentId("1");
// Create a |SignHere| tab somewhere on the document for the recipient to sign
$signHere = new \DocuSign\eSign\Model\SignHere();
$signHere->setXPosition($random);
$signHere->setYPosition($random);
$signHere->setDocumentId("1");
$signHere->setPageNumber("1");
$signHere->setRecipientId("1");
// add the signature tab to the envelope's list of tabs
$tabs = new DocuSign\eSign\Model\Tabs();
$tabs->setSignHereTabs(array($signHere));
// add a signer to the envelope
$signer = new \DocuSign\eSign\Model\Signer();
$signer->setEmail($recipientEmail);
$signer->setName($recipientName);
$signer->setRecipientId("1");
$signer->setTabs($tabs);
$signer->setClientUserId($recipientId);  // must set this to embed the recipient!
// Add a recipient to sign the document
$recipients = new DocuSign\eSign\Model\Recipients();
$recipients->setSigners(array($signer));
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
$envelop_definition->setEmailSubject("[DocuSign PHP SDK] - Please sign this doc");
// set envelope status to "sent" to immediately send the signature request
$envelop_definition->setStatus("sent");
$envelop_definition->setRecipients($recipients);
$envelop_definition->setDocuments(array($document));
// create and send the envelope! (aka signature request)
$envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, null);
echo "<b>Envelope Details: </b><pre>".$envelop_summary ."</pre></br>";

/////////////////////////////////////////////////////////////////////////
// STEP 3:  Request Recipient View (aka signing URL)
/////////////////////////////////////////////////////////////////////////
// instantiate a RecipientViewRequest object
$recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest();
// set where the recipient is re-directed once they are done signing
$recipient_view_request->setReturnUrl("https://www.docusign.com/develcenter");
// configure the embedded signer 
$recipient_view_request->setUserName($recipientName);
$recipient_view_request->setEmail($recipientEmail);
// must reference the same clientUserId that was set for the recipient when they 
// were added to the envelope in step 2
$recipient_view_request->setClientUserId($recipientId);
// used to indicate on the certificate of completion how the user authenticated
$recipient_view_request->setAuthenticationMethod("email");
// generate the recipient view! (aka embedded signing URL)
$signingView = $envelopeApi->createRecipientView($accountId, $envelop_summary->getEnvelopeId(), $recipient_view_request);
echo "</br> Signing URL = <a href='" . $signingView->getUrl() . "' target='_blank'>".$signingView->getUrl()."</a></br>";




//MEthod for embedded sending view
$return_url="https://www.docusign.com/devcenter";
$senderView = $envelopeApi->createSenderView($accountId, $envelopeId, 
$return_url);
var_dump($senderView->getUrl());

Upvotes: 0

Views: 868

Answers (1)

Praveen Reddy
Praveen Reddy

Reputation: 7383

If you want to place additional fields on the document as a sender, you should use the Embedded Sending (or Sender View)

The Embedded Sending view of an envelope allows users to edit the tabs, documents, recipients, and other settings of draft envelopes before sending them out for approval. Similar to Embedded Signing, your app or website can generate a sending URL and integrate directly into your workflow using a Redirect, Webview, or an iFrame.

See here for the code sample.


Q : How to get the url of that document after he has signed it so that i can view it later.

See this answer.

Upvotes: 1

Related Questions