My scenario would be this flow in my application: Register > Sign Document > Return to Finish Page.
The user register on my application and he need to sign a document to finish his registration. He is not a DocuSign user. At the moment all my tests are at the Sandbox environment.
The envelope creation works great. If I don't use the client_user_id it sends the email for signing. But I need to use the client_user_id to use the embedded signing and get the URL for next step.
When I try to to get the URL of the envelope, I receive the following error:
errorCode: SHARED_VIEW_USER_LACKS_PERMISSION
message: User lacks shared permission to envelope. Only a user with shared access to the envelope may perform the requested operation.
Here is the code I'm using on my PHP application to try to get the URL of the recent created envelope:
$envelope = $this->docusignlib->create_document_for_signing($user, $file);
$result = $this->docusignlib->get_url_document($user, $envelope['envelope_id'], $return_url);
public function create_document_for_signing($user, $file)
{
# Document
$document = new DocuSign\eSign\Model\Document([
'document_base64' => base64_encode(file_get_contents($file)),
'name' => 'Document name',
'file_extension' => 'pdf',
'document_id' => '1'
]);
# Sign Here Position
$signHere = new DocuSign\eSign\Model\SignHere([
'document_id' => '1', 'page_number' => '2', 'recipient_id' => '1',
'tab_label' => 'Sign here', 'x_position' => '100', 'y_position' => '720'
]);
# The signer object
$signer = new DocuSign\eSign\Model\Signer([
'email' => $user->user_email,
'name' => $user->user_name,
'recipient_id' => "1",
'client_user_id' => $user->user_id,
'tabs' => new DocuSign\eSign\Model\Tabs([
'sign_here_tabs' => [$signHere]
])
]);
# Next, create the top level envelope definition and populate it.
$envelopeDefinition = new DocuSign\eSign\Model\EnvelopeDefinition([
'email_subject' => "Email subject",
'documents' => [$document],
'recipients' => new DocuSign\eSign\Model\Recipients(['signers' => [$signer]]),
'status' => "sent"
]);
$config = new DocuSign\eSign\Configuration();
$config->setHost($this->api);
$config->addDefaultHeader("Authorization", "Bearer " . $this->accessToken);
$apiClient = new DocuSign\eSign\Client\ApiClient($config);
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
return $envelopeApi->createEnvelope($this->accountId, $envelopeDefinition);
}
public function get_url_document($user, $envelopeId, $returnUrl)
{
$recipientViewRequest = new DocuSign\eSign\Model\RecipientViewRequest([
'user_name' => $user->user_name,
'email' => $user->user_email,
"recipient_id" => "1",
"client_user_id" => $user->user_id,
"authentication_method" => "email",
"return_url" => $returnUrl
]);
$config = new DocuSign\eSign\Configuration();
$config->setHost($this->api);
$config->addDefaultHeader("Authorization", "Bearer " . $this->accessToken);
$apiClient = new DocuSign\eSign\Client\ApiClient($config);
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
return $envelopeApi->createEnvelopeRecipientSharedView($this->accountId, $envelopeId, $recipientViewRequest);
}
I couldn't find ANYTHING related to this error on the documentation and I checked all the permissions and everything seems ok. I'm using the admin user of my demoaccount. Any ideas what I'm doing wrong here?
Thanks!
SHARED_VIEW_USER_LACKS_PERMISSION is about the user and the account. You may want to try a different account and/or a new envelope. I would also ensure that you are making API call to demo.docusign.net URL and not www.docusign.net since you are still in demo/sandbox.
The accessToken should match the account and if you're using the token generator, it's the account that you used when token generator prompted you to log in.
Related
I want to request docusign remote signing by email in laravel.
Can anyone provide me the code for this?
https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/eSignature/SigningViaEmailService.php has code that shows you how to do this.
The relevant PHP code is this:
public static function make_envelope(array $args, $clientService, $demoDocsPath, $docxFile, $pdfFile): EnvelopeDefinition
{
$envelope_definition = new EnvelopeDefinition([
'email_subject' => 'Please sign this document set'
]);
$doc1_b64 = base64_encode($clientService->createDocumentForEnvelope($args));
# read files 2 and 3 from a local directory
# The reads could raise an exception if the file is not available!
$content_bytes = file_get_contents($demoDocsPath . $docxFile);
$doc2_b64 = base64_encode($content_bytes);
$content_bytes = file_get_contents($demoDocsPath . $pdfFile);
$doc3_b64 = base64_encode($content_bytes);
$document1 = new Document([ # create the DocuSign document object
'document_base64' => $doc1_b64,
'name' => 'Order acknowledgement', # can be different from actual file name
'file_extension' => 'html', # many different document types are accepted
'document_id' => '1' # a label used to reference the doc
]);
$document2 = new Document([ # create the DocuSign document object
'document_base64' => $doc2_b64,
'name' => 'Battle Plan', # can be different from actual file name
'file_extension' => 'docx', # many different document types are accepted
'document_id' => '2' # a label used to reference the doc
]);
$document3 = new Document([ # create the DocuSign document object
'document_base64' => $doc3_b64,
'name' => 'Lorem Ipsum', # can be different from actual file name
'file_extension' => 'pdf', # many different document types are accepted
'document_id' => '3' # a label used to reference the doc
]);
# The order in the docs array determines the order in the envelope
$envelope_definition->setDocuments([$document1, $document2, $document3]);
# Create the signer recipient model
$signer1 = new Signer([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'recipient_id' => "1", 'routing_order' => "1"]);
$cc1 = new CarbonCopy([
'email' => $args['cc_email'], 'name' => $args['cc_name'],
'recipient_id' => "2", 'routing_order' => "2"]);
return SMSDeliveryService::addSignersToTheDelivery($signer1, $cc1, $envelope_definition, $args);
}
I have created a template using a base document (a customer contract) the details of which will change when I send out an envelope but the layout will remain the same. I am trying to replace the base document from the template when creating the envelope. I read from the manual that I need to call the EnvelopeDocuments:update method. Is this correct, if so how do I implement that?
Here is what I tried below that threw an error that I am unable to figure out.
**Updated code 2/1/21 for composite templates:
private function make_envelope(array $args): EnvelopeDefinition
{
// create roles for signers
$signer = new Signer([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'role_name' => "signer", 'recipient_id' => "1",
]);
# Create the company signer recipient
$companySigner = new Signer([
'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'],
'role_name' => "companySigner", 'recipient_id' =>"2"
]);
# Recipients object:
$recipients_server_template = new Recipients([
'signers' => [$signer, $companySigner]]);
# Create a composite template
$comp_template1 = new CompositeTemplate([
'composite_template_id' => "1",
'server_templates' => [
new ServerTemplate([
'sequence' => "1", 'template_id' => $args['template_id']])
],
# Add the roles via an inlineTemplate
'inline_templates' => [
new InlineTemplate([
'sequence' => "1",
'recipients' => $recipients_server_template])
]
]);
# Create the pdf document that will be added to the envelope
$doc_file = 'Fiber_Connect_Customer_Agreement.pdf';
$content_bytes = file_get_contents(self::DEMO_DOCS_PATH . $doc_file);
$base64_file_content = base64_encode($content_bytes);
# Create the document model
$documentUpdated = new Document([ # create the DocuSign document object
'document_base64' => $base64_file_content,
'name' => 'Prepared Fiber Connect Customer Agreement', # can be different from actual file name
'file_extension' => 'pdf', # many different document types are accepted
'document_id' => '1' # a label used to reference the doc
# Create a composite template for the added document
$comp_template2 = new CompositeTemplate([
'composite_template_id' => "2",
# Add the recipients via an inlineTemplate
'inline_templates' => [
new InlineTemplate([
'sequence' => "2"])
],
'document' => $documentUpdated]);
# Create the envelope definition with the composited templates
$envelope_definition = new EnvelopeDefinition([
'status' => "sent",
'composite_templates' => [$comp_template1, $comp_template2]
]);
return $envelope_definition;
}
What you need to use are compositeTemplates. We have a pretty good guide on it here: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-composite-template-embedded/
What you need to do is to create your template with the "base document" and when you're creating the envelope, you'd need to replace the base document from the serverTemplate by specifying the document field.
Let us know if you encounter any issues while getting this to work.
I was able to edit the code which is now working again if anyone is interested for the future.
/**
* Creates envelope definition using composite templates
* Parameters for the envelope: signer_email, signer_name, signer_client_id
*
* #param $args array
* #return mixed -- returns an envelope definition
*/
private function make_envelope(array $args): EnvelopeDefinition
{
// create roles for signers
$signer = new Signer([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'role_name' => "signer", 'recipient_id' => "1",
]);
# Create the company signer recipient
$companySigner = new Signer([
'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'],
'role_name' => "companySigner", 'recipient_id' => "2"
]);
# Recipients object:
$recipients_server_template = new Recipients([
'signers' => [$signer, $companySigner]
]);
# Create the pdf document that will be added to the envelope
$doc_file = 'Customer_Agreement_ADOBE_TABS.pdf';
$content_bytes = file_get_contents(self::DEMO_DOCS_PATH . $doc_file);
$base64_file_content = base64_encode($content_bytes);
# Create the document model
$documentUpdated = new Document([ # create the DocuSign document object
'document_base64' => $base64_file_content,
'name' => 'Updated Prepared Fiber Connect Customer Agreement', # can be different from actual file name
'file_extension' => 'pdf', # many different document types are accepted
'document_id' => '1' # a label used to reference the doc
]);
# Create a composite template for the added document
$comp_template1 = new CompositeTemplate([
'composite_template_id' => "1",
'document' => $documentUpdated,
'server_templates' => [
new ServerTemplate([
'sequence' => "1", 'template_id' => $args['template_id']
])
],
# Add the roles via an inlineTemplate
'inline_templates' => [
new InlineTemplate([
'sequence' => "1",
'recipients' => $recipients_server_template
])
]
]);
# Create the envelope definition with the composited templates
$envelope_definition = new EnvelopeDefinition([
'status' => "sent",
'composite_templates' => [$comp_template1]
]);
return $envelope_definition;
}
I use Onesignal notifications for the app.
I don't have a problem sending the notifications but wanted to send these notifications using API help and this library.
php-onesignal library
The notifications I sent must be opened on the relevant page in the application. For this reason, I do not know how to write the URL in the code section below.
require_once(dirname(__FILE__).'/vendor/autoload.php');
use CWG\OneSignal\OneSignal;
$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';
$deviceID = '69aeecc1-7b58-44d1-8000-7767de437adf';
$api = new OneSignal($appID, $authorizationRestApiKey);
$retorno = $api->notification->setBody('Ola')
->setTitle('Titulo')
->addDevice($deviceID)
->send();
I entered the addTag section as in the Onesignal panel, but I could not run it.
$retorno = $api->notification->setBody('Ola')
->setTitle('Titulo')
->addTag('url', 'http://www.example.com/news/testtitle')
->send();
print_r($retorno);
How can I use it here in the Url section of the "ADDITIONAL DATA" field?
Can I solve this problem with addTag?
The following will send a notification with the $data['data'] as additional, as you want.
$data = [
'headings' => ['en' => 'Case 123'],
'contents' => ['en' => 'Case assigned ' . date('d-m-Y H:i')],
'data' => [
'type' => 'new',
'user_id' => 123,
'url' => 'http://www.example.com/news/testtitle'
],
];
OneSignal::sendNotificationCustom([
'app_id' => 1234,
'api_key' => abcd,
'included_segments' => ['All'],
'headings' => $data['headings'],
'contents' => $data['contents'],
'data' => $data['data'],
]);
I am trying to establish connection between my Application and DocuSign Sandbox.
I'am using JWT Authorization.
I have Integration key with RSA private key generated.
I have user to impersonate with GUID and consent aquired
I call https://account-d.docusign.com/oauth/token with proper data which response with success and give me back Access token
Everything works well until this moment.
I've downloaded library for PHP "docusign/esign-client"
and used this fragment of code:
$recipientId = uniqid(5);
$clientUserId = uniqid(5);
$document = new Document([
'document_base64' => $base64FileContent,
'name' => 'Application Form',
'file_extension' => 'pdf',
'document_id' => '1'
]);
$signer = new Signer([
'email' => $email,
'name' => $name,
'recipient_id' => $recipientId,
'routing_order' => "1",
'client_user_id' => $clientUserId,
]);
$signHere = new SignHere([
'document_id' => '1', 'page_number' => '3', 'recipient_id' => $recipientId,
'tab_label' => 'SignHereTab', 'x_position' => '195', 'y_position' => '147'
]);
$signer->setTabs(new Tabs(['sign_here_tabs' => [$signHere]]));
$envelopeDefinition = new EnvelopeDefinition([
'email_subject' => "Please sign this document",
'documents' => [$document],
'recipients' => new Recipients(['signers' => [$signer]]),
'status' => "sent"
]);
$config = new Configuration();
$config->setHost('https://demo.docusign.net/restapi');
$config->addDefaultHeader("Authorization", "Bearer " . $accessToken);
$config->setAccessToken($accessToken);
$apiClient = new ApiClient($config);
$envelopeApi = new EnvelopesApi($apiClient);
$results = $envelopeApi->createEnvelope($integrationKey, $envelopeDefinition);
The result is an error (400) comes from API with info:
PARTNER_AUTHENTICATION_FAILED
The specified Integrator Key was not found or is disabled. Invalid account specified for user.
It says integration key is wrong but few lines before I used this integration key to generate Access Token with success.
Do you have any idea whats is going wrong ?
Before JWT integrations, I was using different integration key and access token from OAuth Token Generator and it worked fine (this previous key didn't have RSA generated)
Could you guys help me with that issue ?
If any more informations could help to find a solution just let me know and I will update my post.
Thanks for help.
The issue is in this line
$results = $envelopeApi->createEnvelope($integrationKey, $envelopeDefinition);
The first parameter of the createEnvelope method should be the Account ID, not the integrator key.
After you receive the access token, you can make a UserInfo call and pull the account ID from that.
Currently Using:
Laravel 5.5
"tucker-eric/docusign-rest-client": "^1.0",
"tucker-eric/laravel-docusign": "^0.1.1"
Intention is to generate a URL so all customers / agents sign on the spot
Here is what I have so far
I first create the client
$client = new DocuSign\Rest\Client([
'username' => env('DOCUSIGN_USERNAME'),
'password' => env('DOCUSIGN_PASSWORD'),
'integrator_key' => env('DOCUSIGN_INTEGRATOR_KEY'),
'host' => env('DOCUSIGN_HOST')
]);
For each signer I assign their name and email
$templateRole1 = $client->templateRole([
'email' => 'abc#gmail.com',
'name' => 'abc',
'role_name' => 'Agent'
]);
$templateRole2 = $client->templateRole([
'email' => 'abc123#gmail.com',
'name' => 'abc',
'role_name' => 'Purchaser 1'
]);
$templateRole3 = $client->templateRole([
'email' => 'abc124#gmail.com',
'name' => 'abc124',
'role_name' => 'Purchaser 2'
]);
$templateRole4 = $client->templateRole([
'email' => 'abc125#gmail.com',
'name' => 'abc125',
'role_name' => 'Seller'
]);
I create the envelope (not sure why it sends it, I dont want it sent yet
$envelopeDefinition = $client->envelopeDefinition([
'status' => 'sent',
'email_subject' => '[DocuSign PHP SDK] - Signature Request Sample',
'template_id' => '***abc-123-',
'template_roles' => [
$templateRole1,
$templateRole2,
$templateRole3,
$templateRole4,
],
]);
Envelope options just because even tho I don't have any
$envelopeOptions = $client->envelopes->createEnvelopeOptions([]);
Creates the final envelope
$envelopeSummary = $client->envelopes->createEnvelope($envelopeDefinition, $envelopeOptions);
Prepare the embedding so I can extract the URL
$envelopeApi = $client->envelopes;
$recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest();
$recipient_view_request->setReturnUrl('https://www.example.net/callback/docusign');
$recipient_view_request->setClientUserId((string) $client->getAccountId());
$recipient_view_request->setAuthenticationMethod("None");
try {
$signingView = $envelopeApi->createRecipientView($client->getAccountId(), $envelopeSummary->getEnvelopeId(), $recipient_view_request);
} catch (DocuSign\eSign\ApiException $e){
echo "Error connecting Docusign : " . $e->getResponseBody()->errorCode . " " . $e->getResponseBody()->message;
}
Which returns:
object(DocuSign\eSign\Model\ErrorDetails)#419 (1) { ["container":protected]=> array(2) { ["error_code"]=> string(20) "INVALID_REQUEST_BODY" ["message"]=> string(94) "The request body is missing or improperly formatted. Input string was not in a correct format." } } Error connecting Docusign : INVALID_REQUEST_BODY The request body is missing or improperly formatted. Input string was not in a correct format.done
My question is what I'm doing wrong to get this error returned, and why is it sending the email to the people signing as I didn't explicitly tell it
Thanks
I'm not familiar with the DocuSign Laravel facades by Eric Tucker. If you need to add attributes beyond what Eric's facades provide then you'll need to fork that project to add support for the additional attributes.
You have a server-resident template. You want to use it to provide an embedded signing ceremony in your Laravel app for the signers.
For a signer recipient to be marked as an embedded signer, set the client_user_id attribute to the signer object. For example:
$templateRole1 = $client->templateRole([
'email' => 'abc#gmail.com',
'name' => 'abc',
'role_name' => 'Agent',
'client_user_id' => '1000'
]);
Note that the client_user_id should uniquely identify this signer as a user within your application.
Re: Why are the signers receiving email invites to sign?
Setting the client_user_id will suppress the email notification to the signer.
Re: should the envelope be sent or be in draft status?
You want sent status, which enables recipients to sign via the embedded signing ceremony you'll be next creating.
Re: Envelope Options for creating the envelope.
Normally, you don't supply an EnvelopeOptions when creating an envelope with the PHP SDK. However, Eric Tucker could be combining calls or something. You'll need to check his code.
Here is a standard PHP call to send an envelope:
$config = new \DocuSign\eSign\Configuration();
$config->setHost($args['base_path']);
$config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
$api_client = new \DocuSign\eSign\ApiClient($config);
$envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
$results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
$envelope_id = $results->getEnvelopeId();
Obtaining the redirect URL for the embedded signing ceremony
Normal PHP way to do this is to call the createRecipientView method. You need to provide the signer's name, email, and client_user_id from the create envelope step, along with the authentication method your app is using to identify the signer. And, of course, the envelope id too.
Example:
# Create the Recipient View request object
$authentication_method = 'None'; # How is this application authenticating
# the signer? See the `authenticationMethod' definition
# https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
$recipient_view_request = new \DocuSign\eSign\Model\RecipientViewRequest([
'authentication_method' => $authentication_method,
'client_user_id' => $envelope_args['signer_client_id'],
'recipient_id' => '1',
'return_url' => $envelope_args['ds_return_url'],
'user_name' => $envelope_args['signer_name'],
'email' => $envelope_args['signer_email']
]);
# 4. Obtain the recipient_view_url for the signing ceremony
# Exceptions will be caught by the calling function
$results = $envelope_api->createRecipientView($args['account_id'], $envelope_id,
$recipient_view_request);
$redirect_url = $results['url'];