Embedded Templates Walkthrough
Embedded templates allow your users to create and edit templates on your site in an iFrame using hellosign-embedded, Dropbox Sign's official client-side library. Templates are used to make frequently-used documents easier to send for signatures and share with others. They're also a powerful tool for automating workflows and using pre-filled data in your signature requests.
Preliminary
Please complete the steps below before following along with the content.
- Create an API app (login required)
Important
skipDomainVerification
to embed requests created using test_mode
.- Save your API app's Client ID and API Key, which you'll need to use this feature.
Try Dropbox Sign Embedded
To get a feel for how our Dropbox Sign Embedded library works, you can use our Embedded Testing Tool to quickly test any of our Embedded flows without having to write a single line of JavaScript.
You can request a sample document, or use the customclaim_url
or edit_url
that you'll generate in the Server Side section below.Server Side
Allowing your site users to create a template involves first creating a template draft. This draft will be displayed on your site in an embedded iFrame, allowing the user to edit and finalize the template. Note that templates created via the embedded template process will only be accessible through the API.
Creating a Template
- Create a template draft by POSTing an API request to
https://api.hellosign.com/v3/template/create_embedded_draft
with the following parameters:- Payload
- PHP
- C#
- JavaScript
- TypeScript
- Java
- Ruby
- Python
- cURL
{
- "client_id": "37dee8d8440c66d54cfa05d92c160882",
- "title": "Test Template",
- "subject": "Please sign this document",
- "message": "For your approval",
- "signer_roles": [
- {
- "name": "Client",
- "order": 0
- {
- "name": "Witness",
- "order": 1
- "cc_roles": [
- "Manager"
- "merge_fields": [
- {
- "name": "Full Name",
- "type": "text"
- {
- "name": "Is Registered?",
- "type": "checkbox"
- "field_options": {
- "date_format": "DD - MM - YYYY"
- "test_mode": true
- Retrieve the
edit_url
from the API response, which will be a JSON object like the one below. Be sure to also store thetemplate_id
for future referencing of the completed template.{
- "template": {
- "template_id": "61a832ff0d8423f91d503e76bfbcc750f7417c78",
- "expires_at": 1427306768
- Set up the frontend. If you are using a modern module bundler with npm, simply install
hellosign-embedded
. Otherwise, our library can be downloaded manually, compiled from source, or imported from our CDN.npm install hellosign-embedded
- Create a new Embedded client. Import the
hellosign-embedded
module instantiate a new client.import HelloSign from 'hellosign-embedded'; const client = new HelloSign({ clientId: 'Your API client ID' });
- Call
client.open()
with theeditUrl
you got from a previous step.client.open(editUrl, { skipDomainVerification: true });
- The embedded iFrame will be displayed and the user will be walked through the process of editing and finalizing the template for future use.
Pre-filled Data
By creating a template draft with merge fields, you are essentially telling your users, "The app can supply this information for you when you use the completed template to send a signature request."
This can be useful if, for example, your app stores contact information. If a user sends a signature request to one of the contacts in your system, you can pre-populate the signature request with contact details prior to sending. It's necessary to provide these details as 'merge fields' during the template creation because it indicates where the data should be placed within the document when sending the signature request.
As explained in the creating a template section, merge fields are specified during the template draft creation API request as a JSON array. Each merge field must have a unique name, and this is enforced by the API.
When the user is presented with the template draft editor, they are allowed to place these merge fields in the document. Merge fields appear to the user as standard Textbox and Checkbox fields. When one of these fields is placed on the document, the context menu will display the app as an option for the data source (in the "Who fills this out?" dropdown list), and the names of any pre-defined merge fields are listed in the dropdown underneath "What text goes here?".
Once the template is saved, the data to populate these merge fields can be specified in the API call to create a signature request. This not only saves the user time, but also ensures better data accuracy. To populate the merge fields, simply execute a /signature_request/send_with_template and use thecustom_fields
parameter, or supply the same parameter when creating an embedded draft for previewing (see previewing a signature request below).Editing a Template
If a template was created using Embedded Templates, then you can also allow your users to edit it by calling /embedded/edit_url/{template_id} and opening theedit_url
with hellosign-embedded. At the time of writing, you cannot use Embedded Templates to edit a template created on hellosign.com.- Make a GET or POST request to /embedded/edit_url/{template_id}.
Note: A POST request is required if any changes are being made to merge fields or editor options.
test_mode
is optional with a POST request, however, it is required for users on Essentials and Standard plans.- Payload
- PHP
- C#
- JavaScript
- TypeScript
- Java
- Ruby
- Python
- cURL
application/json{
- "cc_roles": [
- ""
- "merge_fields": [ ]
- Retrieve the
edit_url
from the API response, which will be a JSON object like the one below. This URL will be used in the same manner as theedit_url
retrieved for the template draft creation.{
- "embedded": {
- "expires_at": 1634313821
- Set up the frontend. Check out the Client Side section below for a tutorial on how to set up the Embedded library.
- Call
client.open()
with theeditUrl
you got from a previous step.client.open(editUrl, { skipDomainVerification: true });
- The embedded iFrame will be displayed and the user will be walked through the process of editing and finalizing the template.
Previewing a Signature Request
When your site user needs to send a signature request based on a template, you will need to create an embedded signature request draft. This draft can be opened in an embedded iFrame to allow the user to preview the request prior to sending. Creating the signature request draft for previewing is also a perfect opportunity to populate any pre-defined merge fields that might have been added by the user during the template creation process.
- Create the embedded template draft by making a POST request to /unclaimed_draft/create_embedded_with_template with the following parameters:
- Payload
- PHP
- C#
- JavaScript
- TypeScript
- Java
- Ruby
- Python
- cURL
{
- "client_id": "b6b8e7deaf8f0b95c029dca049356d4a2cf9710a",
- "template_ids": [
- "61a832ff0d8423f91d503e76bfbcc750f7417c78"
- "requester_email_address": "jack@dropboxsign.com",
- "signers": [
- {
- "role": "Client",
- "name": "George",
- "email_address": "george@example.com"
- "ccs": [
- {
- "role": "Accounting",
- "email_address": "accounting@dropboxsign.com"
- "test_mode": false
- Retrieve the
claim_url
from the API response, which will be a JSON object like the one below. This URL will be used in the same manner as theedit_url
for template creation and editing to display the preview to the user.{
- "unclaimed_draft": {
- "signature_request_id": "8e55b3880c62497791dda0f3b4181cfd95f7ddb4",
- "signing_redirect_url": null,
- "requesting_redirect_url": null,
- "test_mode": true
- Set up the frontend. Check out the Client Side section below for a tutorial on how to set up the Embedded library.
- Call
client.open()
with theeditUrl
you got from a previous step.client.open(editUrl, { skipDomainVerification: true });
- The embedded iFrame will be displayed and the user will be given an opportunity to preview and make edits to the signature request prior to sending. Any
custom_fields
parameters supplied to the draft creation API request will be added to the document as well and these fields can also be edited and moved by the user. The user can then send the signature request by clicking "Continue" (or "Send" if the subject and message for the request have already been set).
Client Side
We provide a client-side library that handles the authorization and display of the embedded request using an iFrame. You can use this feature by adding a few lines of JavaScript code.
If you are using a modern module bundler with npm, simply installhellosign-embedded
.npm install hellosign-embedded
If you are not using a modern module bunder like npm, our library can be downloaded manually, compiled from source, or imported from our CDN.
In your app, import thehellosign-embedded
module, instantiate a new client, then invoke open()
with your claimUrl
and API client ID. Note that we're using skipDomainVerification
when calling this method. You can learn more about that in the Domain Restriction section below.import HelloSign from 'hellosign-embedded';
const client = new HelloSign();
client.open(claimUrl, {
clientId: 'Your API client ID',
skipDomainVerification: true
});
Note: It's recommended that you add the following to your document's <head>
to avoid unexpected behavior on small screens. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
.
open()
:Name | Type | Description |
---|---|---|
requestingEmail | string | The email of the account issuing the signature request. Note: This option is only necessary for 'Me and Others' type signature requests. Example: { |
locale | string | The locale code that will be used to determine which language the embedded request will be displayed in. For a list of Dropbox Sign's supported languages, visit our Languages page. If no locale is specified Dropbox Sign will attempt to determine the user's preferred language by their browser settings or fall back to English. Note: Czech ( CS_CZ ) is only supported by Embedded Signing. Example: { |
redirectTo | string | Where the user will be redirected after sending the signature request. Example: { |
allowCancel | boolean | Whether the user should be able to close the iFrame without finishing the request. Default: true . Example: { |
debug | boolean | Allows debug output to print to the console. Default: false .For even more detailed debug output, run localStorage.debug = 'hellosign-embedded:*'; in your developer console and refresh the page. Example: { |
skipDomainVerification | boolean | Whether or not to skip the domain verification step. Default: false .Note: This will only be honored if the signature request was created with test_mode=1 . Example: { |
timeout | number | How long (in milliseconds) to wait for the Dropbox Sign app to initialize before aborting. Default: 30000 (30 seconds). Example: { |
container | HTMLElement | By default a modal will be opened, but by specifying container you can choose a DOM element on the page in which the iFrame will be embedded. Example: { |
Additional Notes
App Approval
In order to ensure that integrations adhere to eSignature regulations and best practices, an app approval is needed prior to moving into production for all customers implementing embedded signing, embedded requesting, embedded templates, and OAuth workflows.
Important
You will still be able to use your app in test mode until it gets approved. Only live/production activity requires approval.
Please refer to the App Approval Section for more detailed information about getting your app approved.
Domain Restriction
When the iFrame is loaded, it will verify the domain of the parent window and ensure it matches the domain name of the API app specified by the client ID. If the domain does not match, the page won't be loaded.
You can disable domain restriction for easier development:
client.open(signUrl, {
// ...
skipDomainVerification: true
});
localhost
. See the documentation for open()
method in the section above.HTTPS Required
The host page must be served over HTTPS. The iFrame is also loaded over HTTPS, and due to browser security restrictions it will not be able to communicate with the parent window if it is not HTTPS. This communication is required to enable features such as iFrame callbacks and closing the iFrame.
To make development easier, the page will still load if the parent window is served over HTTP, however an alert will be displayed to notify you of this requirement. Switch to HTTPS to prevent this alert from being displayed.
Redirection
If a redirect url is specified, the iFrame will redirect users to it after they send the document(s). Data from thesign
event will be appended to the url query string.Signature Links
Signature URLs are only valid for 60 minutes after /embedded/sign_url has been called and expire as soon as they're accessed.
It is best practice to wait until your signer hits the page before generating thesign_url
so the link doesn't expire before the signer is ready. However, since the signature_id
itself does not expire, a fresh sign_url
can always be generated.Text Tags
The embedded functionality can be used in conjunction with Dropbox Sign Text Tags.
Client Side Events
There are a number of events that the client may emit. To listen to these events, pass the event name and a callback function toon()
. An string enumeration of available events can also be found under HelloSign.events
.client.on('sign', (data) => {
console.log('The document has been signed!');
console.log('Signature ID: ' + data.signatureId);
});
Here are a list of possible events:
Event | Description | Data |
---|---|---|
createTemplate | Emitted when the user creates the signature request template. | { |
open | Emitted when the embedded window has opened. | { |
cancel | Emitted when the template was canceled by the user by either pressing the close button or selecting "close" from the dropdown list. | |
finish | Emitted when the user has finished the embedded template flow without cancelling. | |
message | Emitted when embedded has received a cross-origin window message from the app. | { |
close | Emitted when the window has closed. | |
error | Emitted when the app encounters an error. | { |